Regex backreference being inserted instead of match group for project wide searches

Prerequisites

Description

It appears the the regex find all and replace all within a project has a bug. When a file is open the backreference is inserted instead of the captured text. If the file isn’t open, the replace works as it should. This bug doesn’t seem to appear when find all and replace all within a single file.

Steps to Reproduce

  1. create two identical test text files within a folder, with text to search and replace

Screen Shot 2020-04-09 at 3 35 31 PM

Screen Shot 2020-04-09 at 3 30 35 PM

  1. Crate a regex search w/ replacement using backreference, leaving one file open..
    image

  2. Select Replace All

Screen Shot 2020-04-09 at 3 41 12 PM

Expected behavior:

It would be expected that the search & replace would work in both files

Actual behavior:
In the file that was open, the backreference is inserted, instead of match:
Screen Shot 2020-04-09 at 3 42 05 PM

And the file that was closed performed as expected:
Screen Shot 2020-04-09 at 3 42 10 PM

Reproduces how often:
Consistently reproduces, in both Linux and MacOS

Versions

Atom : 1.45.0
Electron: 4.2.7
Chrome : 69.0.3497.128
Node : 10.11.0

Additional Information

Thank you, love atom : )

2 thoughts on “Regex backreference being inserted instead of match group for project wide searches

  1. Hey @m4rk3r, thanks for the report.

    Reproduced in Atom 1.44.0 stable and 1.47.0-5 Nightly


    Search Type: Regex
    Regex: \&(\w+)
    Test File Extension: .txt
    Simplified Test Content: &test
    Expectations Summary: The file that is closed works as expected, the open inserts the backreference instead of the actual value.

    Closed File Result
    Screen Shot 2020-04-10 at 1 38 59 PM

    Open File Result (The Bug Here)
    Screen Shot 2020-04-10 at 1 39 19 PM

  2. This seems to have been fixed with this commit to the text-buffer repo. Before that, occurrences plain-text replaced. This didn’t happen to files which are closed because of the different handling of open editors (for which unsaved buffers may exist) and ‘untouched’ files for which the search-and-replace is done by another library. That difference is found here.