-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Labels
bugA bug.A bug.
Description
Using ripgrep 13.0.0 on Ubuntu 22.10, the argument --passthru adds a new line at the end of data (so it can't be used to get only changes explicitly requested with the -r argument). It seems to be a bug, the documentation doesn't refer to adding a newline, but only Print both matching and non-matching lines, implying that data should be the same at the end of the process (unless replacements occur).
Example of the issue:
$ echo -n abc$'\n'def | rg --passthru 'b' -r 'B' | xxd -g 1
00000000: 61 42 63 0a 64 65 66 0a aBc.def.Expected result: no newline added at the end, like sed or other similar tools:
$ echo -n abc$'\n'def | sed 's/b/B/g' | xxd -g 1
00000000: 61 42 63 0a 64 65 66 aBc.def
$ echo -n abc$'\n'def | perl -pe 's/b/B/g' | xxd -g 1
00000000: 61 42 63 0a 64 65 66 aBc.def
$ echo -n abc$'\n'def | tr 'b' 'B' | xxd -g 1
00000000: 61 42 63 0a 64 65 66 aBc.defHere's an example with diff:
$ cat lorem.txt | xxd -g 1
00000000: 6c 6f 72 65 6d 0a 69 70 73 75 6d lorem.ipsum
$ rg --passthru -e lorem -r Lorem lorem.txt | sponge lorem.txt
$ git diffThe same process with sed results in a different output for diff:
$ git restore lorem.txt
$ sed -i 's/lorem/Lorem/g' lorem.txt
$ git diffMetadata
Metadata
Assignees
Labels
bugA bug.A bug.

