Skip to content
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

Reading patterns from file (-f) loses last character #1259

Closed
dprobinson opened this issue Apr 19, 2019 · 3 comments
Closed

Reading patterns from file (-f) loses last character #1259

dprobinson opened this issue Apr 19, 2019 · 3 comments
Labels
bug A bug.

Comments

@dprobinson
Copy link

What version of ripgrep are you using?

ripgrep 11.0.1 (rev a622293)
-SIMD -AVX (compiled)
+SIMD -AVX (runtime)

How did you install ripgrep?

Compiled from source

What operating system are you using ripgrep on?

Arch Linux

Describe your question, feature request, or bug.

When reading patterns in from a file using the "-f" flag, it appears that the last character is lost. Depending on the last character in the patterns file, this causes either a parsing error, or the silent use of a truncated pattern.

If this is a bug, what are the steps to reproduce the behavior?

Create the patterns file (patterns.txt):

THIS
is
a
test
[broken]

N.B. Ensure a blank newline is not added at the end of the file by your editor (see bug #783)

Run the following command (you can use any file as the corpus, as we don't get as far as loading it):

rg -P -f patterns.txt testfile

If this is a bug, what is the actual behavior?

ripgrep reports that there's a parsing error, indicating that the last char "]" has been lost whilst loading the patterns from the file:

PCRE2: error compiling pattern at offset 22: missing terminating ] for character class

If you modify the patterns.txt file to the following, you no longer receive an error, even though the pattern is now invalid, leading me to believe that the last char is discarded:

THIS
is
a
test
[broken]]

If this is a bug, what is the expected behavior?

Read the last character of the file when loading patterns using "-f", omitting only a trailing newline, as per #783

@BurntSushi BurntSushi added the bug A bug. label Apr 19, 2019
@BurntSushi
Copy link
Owner

Fixed in e7829c0

@BurntSushi
Copy link
Owner

Thanks for reporting this! I don't think this was a regression in the latest release, so I don't know whether I'll cut a new patch release just for this or not. In the mean time, you can add a \n as a work-around. But this should be fixed on master now!

@dprobinson
Copy link
Author

Just recompiled from master, and I can confirm it appears to be fixed in e7829c0.

Thanks for the ridiculously fast fix, and for writing such a great tool!

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

No branches or pull requests

2 participants