Skip to content

Preserve line terminator type when using --crlf and -r #3100

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IsaacOscar
Copy link

This fixes a minor issue where the --crlf in combination with -r / --replace option causes matched lines to have there line terminators changed to \r\n, consider for example the following Fish shell line:

# printf 'hello\nworld\r\n' | rg --crlf '.' -r '$0' | string escape

Without this pull request, it prints:

hello\r
world\r

(So hello has magically had an \r added after to it)

With my pull request, the above prints:

hello
world\r

With this change, -r '$0' is now a no-op, i.e. rgs behaviour is now the same as if it was omitted.

(Note that a \r\n will still be inserted when the file does not end in a newline of any sort:

# printf 'hello\nworld' | rg --crlf '.' -r '$0' | string escape
hello
world\r

see issue #3097.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant