-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Reading patterns from file (-f) loses last character #1259
Description
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