Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline regex with capture group substitutes $1 literally until Replace Preview is opened #63297

Closed
Simran-B opened this issue Nov 16, 2018 · 12 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug search Search widget and operation issues verified Verification succeeded
Milestone

Comments

@Simran-B
Copy link

Version: 1.30.0-insider (but also seen in released 1.29.0)
Commit: 24b0f75
Date: 2018-11-16T06:20:02.054Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

Steps to Reproduce:

  1. Create a folder multiline-capture

  2. Create a file test.md inside the folder with the following content:

    Use a loop to iterate over an array and
    print something.
    
  3. Open the folder in vscode

  4. Open Search panel, enable regex option and use: (array).+\n and $1

  5. Hit return or Refresh. The preview in the search panel shows:

    a loop over an array and$1

  6. Click on it to open the Replace Preview.
    It confirms that the match will be replaced by a literal $1

  7. Close the Replace Preview. In this moment, the preview in the search panel changes to:

    a loop over an array andarray

  8. Click on it again to open the full preview and see it confirmed that it will replace it by the capture group value array now.

  9. Refresh the search. It goes back to $1

  10. If you use Replace All, the result is as shown in the preview, so the match is either replaced by $1 or array depending on what it showed before you replaced all occurrences.

  11. Remove \n from the expression and refresh search: The issue does not occur, the preview shows array as substitute value immediately.

image
image

Expected behavior:
I expect it to replace the match with the content of the capture group (which is array) all the time.

Does this issue occur when all extensions are disabled?: Yes

@vscodebot
Copy link

vscodebot bot commented Nov 16, 2018

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@vscodebot vscodebot bot added the search Search widget and operation issues label Nov 16, 2018
@roblourens
Copy link
Member

roblourens commented Nov 22, 2018

Can you check whether this works in the latest insiders? It sounds the same as #62980 and this scenario works for me now. But the version you posted above "should" have had that fix already...

@roblourens roblourens added the info-needed Issue requires more information from poster label Nov 22, 2018
@Simran-B
Copy link
Author

Simran-B commented Nov 22, 2018

The problem still occurs in

Version: 1.30.0-insider
Commit: 0d3a144
Date: 2018-11-22T06:17:03.696Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
OS: Windows_NT x64 10.0.17134

Which Regex engine is actually used here? Are both (JS and Rust via ripgrep) involved here somehow and are not fully interchangeable perhaps?

BTW. I turned on search.usePCRE2 to see if it makes a difference, but observe the same faulty behavior.

@roblourens roblourens added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Nov 26, 2018
@roblourens
Copy link
Member

I see it now. Windows only.

@roblourens roblourens added this to the November 2018 milestone Nov 26, 2018
@NilsEnevoldsen
Copy link

This is happening for me on macOS, @roblourens.

@roblourens
Copy link
Member

In the latest Insiders build? Mac will also fail on 1.29

@NilsEnevoldsen
Copy link

Sorry, on 1.29.1. Carry on.

@roblourens
Copy link
Member

This fails with CRLF line endings, you can use \r\n in your pattern instead to work around it.

@Simran-B
Copy link
Author

It's only half a work around: I tried (array).+\r\n and the result list shows the expected captured value, but if you open the preview and close it, the match in the result list disappears.

Version: 1.30.0-insider
Commit: d3bb20c
Date: 2018-11-27T08:27:31.447Z

@roblourens
Copy link
Member

Try \r?\n, the editor normalizes away the \r...

@Simran-B
Copy link
Author

Confirmed to be working. I assume the original issue is considered a bug that needs fixing still?

@roblourens
Copy link
Member

Yep

@Tyriar Tyriar added the verified Verification succeeded label Dec 4, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug search Search widget and operation issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

4 participants