Bug 449545 - Replace in "Search and Replace" does not work when the search regex contains lookahead or lookbehind part
Summary: Replace in "Search and Replace" does not work when the search regex contains ...
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: part (other bugs)
Version First Reported In: 21.12.0
Platform: unspecified All
: NOR major
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-03 08:40 UTC by Atanas Uzunov
Modified: 2022-02-11 13:33 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 22.04
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Atanas Uzunov 2022-02-03 08:40:56 UTC
SUMMARY
When the search string entered in the "Search and Replace" plugin is a regular expression with lookahead or lookbehind part, the replace functionality does not work.

STEPS TO REPRODUCE
1. Open Kate and write a simple text in the editor, for ex:
SRC0
SRC1
SRC2

2. Open Search and Replace, enable regular expression search and type the following regex in the search field:
SRC(?=\d)

3. Type any replace string in the replace field, for ex:
DST

3. Press Search. The found lines will display fine.

4. Press Replace or Replace Checked

OBSERVED RESULT
The found "SRC" strings are not replaced with "DST"

EXPECTED RESULT
The found "SRC" strings should be replaced with "DST"

SOFTWARE/OS VERSIONS
Observed in Kate 21.12.0 for Windows, as well as Kate in the unstable branch of KDE Neon.
Qt Version: 5.15.2 (for the Windows version)

ADDITIONAL INFORMATION
In KWrite (in KDE Neon unstable branch), the above steps work fine.
Comment 1 Kåre Särs 2022-02-05 19:24:42 UTC
I can confirm this bug.
Comment 2 Bug Janitor Service 2022-02-06 17:20:57 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/587
Comment 3 Kåre Särs 2022-02-10 05:43:40 UTC
Git commit cb759994beb24b119492e588147be1916390d017 by Kåre Särs.
Committed on 09/02/2022 at 20:14.
Pushed by sars into branch 'master'.

S&R: Fix Look-ahead & behind highlighting & replace

Strip the look-ahead and look-behind from the regular-expression that
checks if a string has been modified after search and returns the
possible captures. We strip the look-ahead/behind because we only
match against the previously found range.

M  +27   -1    addons/search/MatchModel.cpp
M  +6    -0    addons/search/MatchModel.h
A  +48   -0    addons/search/autotest/input/LookaheadLookbehindTestFile.txt
A  +22   -0    addons/search/autotest/input/MultilineStartEndOfLineMatch.txt
M  +2    -9    addons/search/plugin_search.cpp

https://invent.kde.org/utilities/kate/commit/cb759994beb24b119492e588147be1916390d017