Bug 65038 - EDITING: Search&Replace doesn't replace regular expression with Look assertions (ahead-behind)
Summary: EDITING: Search&Replace doesn't replace regular expression with Look assertio...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
4.0.3.3 release
Hardware: Other All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: BSA target:6.5.0
Keywords:
: 111646 136890 (view as bug list)
Depends on:
Blocks: Find-Search
  Show dependency treegraph
 
Reported: 2013-05-27 13:49 UTC by freddi34
Modified: 2024-03-20 04:33 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
FindReplaceLookAssertion.odt (11.18 KB, application/vnd.oasis.opendocument.text)
2016-09-18 12:12 UTC, pierre-yves samyn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description freddi34 2013-05-27 13:49:00 UTC
Problem description: 
The Search&Replace feature does not properly support regular expressions with lookaheads. It is able to find matches that conform with the lookahead, but pressing the replace button does nothing.

Steps to reproduce:
1. You have a text that contains certain combinations of characters, for example AB, and you want to change the formatting of A only if it occurs in front of B.
2. Click Edit → Search & Replace
3. Enter into "Search for": A(?=B)
4. Enter into "Replace by": A
5. While "Replace is focussed, click "Format" and select superscript.
5. Click "Search" and it does find results.
6. Click "Replace".

Current behavior:
The text stays unchanged.

Expected behavior:
The matches (A) should be replaced so that they are formatted in superscript.

              
Operating System: Ubuntu
Version: 4.0.3.3 release
Comment 1 Mirosław Zalewski 2013-06-26 13:50:33 UTC
Hi

I could not reproduce this problem on LO 4.0.4, Debian testing amd64. Following your instructions results in superscripted A just before normal B.

Can you check if problem still applies to newer version?

Best regards
Mirosław Zalewski
Comment 2 David 2014-01-01 10:19:27 UTC
I was just searching for another (potential) regex problem, and ran across this one. Here are my results:

(1) Following OP's instructions *exactly*, I get the *same* result: "AB" remains unchanged.

(2) IF, however, I use "Replace All" instead of "Replace", then the "A" is superscripted.

I have tried this repeatedly, and it is consistent: in this scenario "Replace" finds *but does not replace* the intended string; but "Replace All" correctly performs the operation.

I am using LibO Writer Version: 4.1.4.2 Build ID: 410m0(Build:2) under Linux Mint 13 (LTS; built on Ubuntu Precise 12.04) on a Toshiba Satellite A100.

(I would change the status of this comment to "confirmed", but that's not an option I see. Sorry!)
Comment 3 QA Administrators 2014-08-04 16:17:58 UTC Comment hidden (obsolete)
Comment 4 Mirosław Zalewski 2014-08-04 17:56:36 UTC
I have tried to reproduce this bug again.

LibreOffice 4.2.6.2, Debian testing amd64: bug COULD BE reproduced
LibreOffice 4.0.4.2, Windows 7 x86: bug COULD BE reproduced

Therefore, I am marking this bug as NEW (i.e. confirmed).

As for my previous comment, when I wrote that I could not reproduce this bug - I guess I must have clicked "Replace All" instead of "Replace". As David points out, this bug exists if you click "Replace", but not if you click "Replace All".  Right now, using 4.0.4 (the same version that I used back then), I could reproduce this issue.

Or it might be that this bug did exist, was fixed in 4.0.4 on Linux and then introduced again. But it seems very unlikely.
Comment 5 QA Administrators 2015-09-04 02:49:24 UTC Comment hidden (obsolete)
Comment 6 Buovjaga 2015-11-30 13:33:44 UTC
Still repro.

Win 7 Pro 64-bit Version: 5.2.0.0.alpha0+
Build ID: a7c3a2a9be83686657c06f37d521f9f6d2004ddd
Threads 4; Ver: Windows 6.1; Render: default; 
TinderBox: Win-x86@39, Branch:master, Time: 2015-11-28_04:39:18
Locale: fi-FI (fi_FI)
Comment 7 pierre-yves samyn 2016-09-18 12:12:45 UTC
Created attachment 127405 [details]
FindReplaceLookAssertion.odt
Comment 8 pierre-yves samyn 2016-09-18 12:19:43 UTC
Hi

More information (I thought to create a new report, but as I was going to use exactly the same title...)

Problem also occurs with look-behind assertion.

Steps to reproduce:

1. File> Open> FindReplaceLookAssertion.odt attached
2. Edit> Find & Replace
3. Find: (?<=\()[^)]+(?=\))
4. Click Find All

Expected & actual results: text *into* parentheses selected

5. Replace: &test
6. Other options untick "Current selection only"
7. Replace All

Expected result: test added before all )
Actual result: "&" is not interpretated (added as text)

Note: same replacement is ok with Calc

Regards
Comment 9 Xisco Faulí 2017-09-29 08:52:25 UTC Comment hidden (obsolete)
Comment 10 Mike Kaganski 2019-12-19 07:44:18 UTC
In tdf#75806, leading characters were added to analyzed part of string in TextSearch::searchForward. This fixes look-behind assertions. To handle look-ahead assertions, similarly trailing characters need to be added there.
Comment 11 Mike Kaganski 2019-12-19 08:44:12 UTC
https://gerrit.libreoffice.org/85487
Comment 12 Mike Kaganski 2019-12-19 09:52:19 UTC
*** Bug 111646 has been marked as a duplicate of this bug. ***
Comment 13 Commit Notification 2019-12-19 09:59:56 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/0cd3b7926cafc01d06b589124215e9cb7c148f19

tdf#65038: use trailing string characters for look-ahead assertions

It will be available in 6.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 14 Xisco Faulí 2020-10-13 08:37:47 UTC
*** Bug 136890 has been marked as a duplicate of this bug. ***