Bug 161932 - Replacing with regular expressions (.*?) shifts direct formatting to the left
Summary: Replacing with regular expressions (.*?) shifts direct formatting to the left
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
24.2.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Find&Replace-Regex
  Show dependency treegraph
 
Reported: 2024-07-06 17:03 UTC by Daniele
Modified: 2024-08-26 21:11 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Test file with results shown (17.67 KB, application/vnd.oasis.opendocument.text)
2024-07-06 17:05 UTC, Daniele
Details
Another teste case (21.41 KB, application/vnd.oasis.opendocument.text)
2024-07-23 16:12 UTC, Daniele
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniele 2024-07-06 17:03:43 UTC
Description:
When searching and replacing characters around a given string containing some italics, the $1 replacement option does not work as espected, that is, it changes which characters are in italics.
Expression used 
Search: (\x20*)([\-|—|–]|\-{1,})([\x20]*)(.*?)([\x20]*)([\-|—|–]|\-{1,})(\x20*)
Replace: –⁠ $4 ⁠–$7
(text example in the attached file)

Steps to Reproduce:
1.Open attached file
2.Apply regular expression to the three portions of the text concerned under the title Before replacement, there are two words in italics: garçons and morceau.
3.After replacement, some italics have been shifted as shown in the same file under the headings: After replacement and Highlighting of the italics changed

Actual Results:
Italics of original shifted

Expected Results:
They should remain where they are


Reproducible: Always


User Profile Reset: Yes

Additional Info:
Version: 24.2.4.2 (AARCH64) / LibreOffice Community
Build ID: 51a6219feb6075d9a4c46691dcfe0cd9c4fff3c2
CPU threads: 8; OS: macOS 14.5; UI render: Skia/Metal; VCL: osx
Locale: en-US (en.UTF-8); UI: en-US
Calc: threaded
Comment 1 Daniele 2024-07-06 17:05:08 UTC
Created attachment 195146 [details]
Test file with results shown

I have the impression that I have already submitted this bug, but I could not find any trace of it in my older bugs or my email.
Comment 2 Daniele 2024-07-21 07:53:51 UTC
Hi, am I meant to submit something to confirm it?
I am changing the release: it still happens.
Comment 3 Stéphane Guillou (stragu) 2024-07-22 07:54:06 UTC
I can confirm that direct formatting of what is between the hyphens shifts to the left by one character. If it is repeated on the same text, it shifts by 2 characters at each run.
Easier to see with text formatted with e.g. highlight.

Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 8705cfecd5a10f817d3a2a02041d85e77282aa30
CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: CL threaded

Version: 24.2.5.2 (X86_64) / LibreOffice Community
Build ID: bffef4ea93e59bebbeaf7f431bb02b1a39ee8a59

In 7.6, formatting wouldn't be kept when the text was replaced.

Formatting started being kept with:

commit 0c3b89da7cde9866bf3174a6276736c76efb8356
author	Matt K 	Thu Aug 03 00:06:24 2023 -0500
committer	Mike Kaganski 	Fri Nov 10 19:05:13 2023 +0100
tdf#62603 Fix find/replace to not extend font attributes
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155274

... which is [2098ffc1b2e5c669ae93d0fca25550c0446dcb2d] in the linux-64-24.2 bibisect repo.

Matt, can you please have a look?
Comment 4 Daniele 2024-07-23 16:12:17 UTC
Hi I am attaching some new test cases in case they shed light on what is happening.
Comment 5 Daniele 2024-07-23 16:12:42 UTC
Created attachment 195456 [details]
Another teste case
Comment 6 Daniele 2024-07-23 16:22:46 UTC
I forgot to mention what I am testing with:

Version: 24.2.5.2 (X86_64) / LibreOffice Community
Build ID: bffef4ea93e59bebbeaf7f431bb02b1a39ee8a59
CPU threads: 8; OS: macOS 14.5; UI render: Skia/Metal; VCL: osx
Locale: en-US (en.UTF-8); UI: en-US
Calc: threaded
Comment 7 Stéphane Guillou (stragu) 2024-07-24 02:53:49 UTC
Thanks for following up, Daniele, but the "Version" field is for "earliest affected". I bibisected the issue to where it started in comment 3, which is 24.2 alpha0.
It's potentially an implementation error, but Matt would know more.
Let's see if a dev can now look into it.