Skip to content

Attempting to use a newline character in pattern with the PCRE2 engine, outside multiline mode fails silently #1261

@dprobinson

Description

@dprobinson

What version of ripgrep are you using?

ripgrep 11.0.1 (rev e7829c0)
-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.

Attempting to use a newline character ("\n") in pattern with the PCRE2 engine (-P), outside multiline mode fails silently.

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

Create the following corpus.txt:

testing
RIP
GREP
again

First, try the search with Rust's engine:

rg "RIP\nGREP" corpus.txt

Output:

the literal '"\n"' is not allowed in a regex

Consider enabling multiline mode with the --multiline flag (or -U for short).
When multiline mode is enabled, new line characters can be matched.

As expected (from the documentation), we see an error.

Now try searching using the PCRE2 engine:

rg -P "RIP\nGREP" corpus.txt

Output:

As we see, we've tried to use a newline char without multiline mode, but receive no error. The search fails silently.

N.B. Searching using the PCRE2 engine, with multiline mode (-U) works as expected:

rg -PU "RIP\nGREP" corpus.txt

Output:

2:RIP
3:GREP

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

See output above

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

I would expect ripgrep to throw an error, warning the user that newlines cannot be matched outside multiline mode (-U) when using PCRE2. This would yield the same behaviour as when Rust's engine is used (#1055)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions