Bug 365642

Summary: behavior of search and replace with escape sequences is wrong and changes from one run to another
Product: [Applications] kate Reporter: kdebugs
Component: searchAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED DUPLICATE    
Severity: normal CC: kare.sars
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.50
Sentry Crash Report:

Description kdebugs 2016-07-14 01:49:41 UTC
As observed in Kate 16.04.1 on Manjaro 64-bit and in 3.14.13 on Ubuntu 32-bit.  The behavior is slightly different with respect to the incorrect number of finds (see below), but it's always wrong and changes in both.


Reproducible: Always

Steps to Reproduce:
1. Make and open a file consisting of 64 newline characters (65 lines), e.g.:
$ printf '\n%.0s' {1..64} > kate-bug-test.txt
$ kate kate-bug-test.txt

2. Press Ctrl-R
Find: \n
Replace: ====\n
Mode: Escape Sequences
click Replace All

3. Close search, press Ctrl-Z to undo.

4. Repeat steps 2-3 several times.


Actual Results:  
YMMV.  For me:

On the newer version:
- cursor position doesn't seem to matter
- 1st time it finds 32 (all the odd-numbered).
- 2nd time it finds 1 (line 64).
- 3rd and following it finds 0.

On the older version:
- 1st time finds 32 (odd lines 1-63)
- 2nd time finds 32 (line 1, even lines 4-64)
- 3rd time finds 31 (line 1, odd lines 5-63)
- 4th time finds 31 (line 1, even lines 6-64)
- 5th time finds 30 (line 1, odd lines 7-63)
- 6th time finds 30 (line 1, even lines 8-64)
etc.


Expected Results:  
Should find and replace '\n' with '====\n' 64 times.
Comment 1 kdebugs 2016-07-14 02:13:32 UTC
NB: regarding "cursor position doesn't seem to matter" that seems to apply to either version.  I initially thought it did matter due to the changing behavior, but forgot to delete that line when I found it didn't.
Comment 2 kdebugs 2016-07-14 02:23:51 UTC
Just a thought: the fact that the behavior changes from one run to another seems to indicate an underlying bug that should be fixed BEFORE the actual behavior is fixed (finding 64, not 32).  If you fix the behavior first, you might lose the ability to reproduce the underlying bug.
Comment 3 Kåre Särs 2016-07-14 06:00:42 UTC
I can confirm this bug. 
NOTE: it is the "escape sequence" mode that is effected not regular-expression
Comment 4 Dominik Haumann 2018-08-15 19:58:58 UTC
 This is fixed for KDE Frameworks 5.50, see bug #381080.

*** This bug has been marked as a duplicate of bug 381080 ***