-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjacent replaced multiline matches result in wrong line numbers #2779
Comments
This is an incomplete description of the problem you're reporting. It isn't just when a regex matches strings that are adjacent, it's also required that you use the
Indeed though, the adjacency part of this seems important. If instead I use the following haystack as
Then the line numbers change:
|
As you say, I forgot to mertion the |
I'm not proficient with Rust, but I could try to look for the problem. Any pointers on where to look? |
Likely in That's where I would start anyway. |
It seems that the problem is we didn't keep track of line number when doing replace using regex package. Within a call of StandardSink::replace, if there are multiple matches we didn't record the line number corresponding to each matches, instead we output the data after replace to sink, in which the line number was counted by number of '\n' which is wrong because some '\n' was modified when we do StandardSink::replace. |
With that said, it minght be hard to get the line number of the replaced result, and it requires some changes in apis to pass the corresponding line number of each replaced result to sink to be used in printing. I wonder would it be easier to do what the the documentation says (#2852), and don't print line number but print index of matches in multi-line search. |
Please tick this box to confirm you have reviewed the above.
What version of ripgrep are you using?
ripgrep 13.0.0
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)
How did you install ripgrep?
APT
What operating system are you using ripgrep on?
Kubuntu 23.10
Describe your bug.
This is similar to #2420, and I understand why that's WONTFIX. This is different though.
Using a multiline regexp, when the regexp matches strings that come immediately one after another, it bungles the line numbers of all of them. Easier to show you with a reproduction example:
What are the steps to reproduce the behavior?
Save a file
test.txt
containing:Then run
What is the actual behavior?
The result is
Only the first hit is correct.
You can see that the line numbers will be correctly reported if you modify the file to add a newline after each instance of ":end:".
What is the expected behavior?
Expected the result:
The text was updated successfully, but these errors were encountered: