Skip to content

rg outputs wrong matches when everything is matched and replaced with custom string #1739

@borestad

Description

@borestad

What version of ripgrep are you using?

ripgrep 12.1.1
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)

How did you install ripgrep?

brew install ripgrep

What operating system are you using ripgrep on?

Darwin 19.6.0 x86_64
zsh 5.8 (x86_64-apple-darwin19.6.0)

Describe your bug.

rg outputs wrong matches when everything is matched and replaced with custom string

What are the steps to reproduce the behavior?

Preparation

❯❯❯ cd $(mktemp -d)
❯❯❯ touch a b c d e

Example1 - When it works

❯❯❯ fd . | rg 'a.*' -r '$0.<NO_EXTENSION>'

a.<NO_EXTENSION>

Example2 - When it fails

❯❯❯ fd . | rg '.*' -r '$0.<NO_EXTENSION>'

a.<NO_EXTENSION>
.<NO_EXTENSION>
b.<NO_EXTENSION>
.<NO_EXTENSION>
c.<NO_EXTENSION>
.<NO_EXTENSION>
d.<NO_EXTENSION>
.<NO_EXTENSION>
e.<NO_EXTENSION>
.<NO_EXTENSION>

What is the expected behavior?

Example2 - How it should behave

❯❯❯ fd . | rg '.*' -r '$0.<NO_EXTENSION>'

a.<NO_EXTENSION>
b.<NO_EXTENSION>
c.<NO_EXTENSION>
d.<NO_EXTENSION>
e.<NO_EXTENSION>

What do you think ripgrep should have done?

Removed the .<NO_EXTENSION> from the output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions