Skip to content

Patterns may affect each other when multiple patterns are provided #2480

@gofri

Description

@gofri

What version of ripgrep are you using?

13.0.0

How did you install ripgrep?

brew

What operating system are you using ripgrep on?

MacOS M1

Describe your bug.

When providing multiple patterns via either -e or -f,
specified flags affect all following patterns.

What are the steps to reproduce the behavior?

Text

What is the actual behavior?

rg respect the case-insensitive flag (?i) from the first pattern in the second pattern as well.

DEBUG|globset|crates/globset/src/lib.rs:421: built glob set; 0 literals, 0 basenames, 12 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
Text

Same goes for:
echo 'MyText' | rg -f <(printf '(?i)notintext\ntext')

What is the expected behavior?

Empty result (the case-insensitive flag should not affect the second pattern).

What do you think ripgrep should have done?

Treat each pattern independently.
Specifically, for these pattern, I'd expect the merged pattern to be:
'(?:(?i)notintext')|(?:'text')
rather than:
'(?i)notintext'|'text'

Side notes:

  1. Works as expected if I manually wrap each pattern as (?:PATTERN)
  2. Works as expected if I replace the first pattern with (?i:notintext)
  3. Works as expected if I replace the order of the patterns (because the effect of the flag only applies "to the right")

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