ruby-lsp icon indicating copy to clipboard operation
ruby-lsp copied to clipboard

fix: Don't escape regex characters in test commands on Windows

Open BillionClaw opened this issue 8 months ago • 7 comments

Fixes #3759

Shellwords.escape() is designed for Unix shells and incorrectly escapes characters like $ on Windows. This causes the "Run Test In Terminal" CodeLens feature to fail on Windows because the regex pattern becomes incorrectly escaped.

Changes:

  • Added escape_for_shell() helper that uses Gem.win_platform? to detect Windows
  • On Windows: returns text unescaped (Windows cmd parsing doesn't need same escaping)
  • On Unix: continues using Shellwords.escape()

BillionClaw avatar Mar 15 '26 21:03 BillionClaw

Fix looks good. Can you sign the CLA please?

rafaelfranca avatar Apr 07 '26 22:04 rafaelfranca

Thank you for the pull request. I think we should go with #4012 instead

rafaelfranca avatar Apr 08 '26 19:04 rafaelfranca

Nevermind, this fix need to happen in multiple place. I do think we should not be escaping on windows for the method name, but we should fix this problem in all places that need to be fixed.

rafaelfranca avatar Apr 08 '26 19:04 rafaelfranca

Friendly bump -- this PR has been open for a while. Happy to make any changes if needed, or close it if no longer relevant.

onthebed avatar Apr 27 '26 22:04 onthebed

Thanks for the review — I agree this branch is broader than it should be. I'll leave 4007 open and let #4012 carry the narrower fix instead.

onthebed avatar Apr 28 '26 17:04 onthebed

Re: the escaping question — the regex content still needs to be preserved, but Shellwords.escape is Unix-shell specific and is the part that breaks the generated command on Windows. So the goal here is not “no escaping at all”, it’s “avoid Unix-style quoting on Windows and keep the regex form intact.” I agree we should add integration coverage that exercises the generated command on both PowerShell and exe.

breezeFur avatar Apr 29 '26 03:04 breezeFur

You're right to push on this. After revisiting it, I don't think the Windows helper in 4007 is the simplest viable fix. The narrower fix is to keep the regex fragments intact and only stop over-escaping the pattern where we know we're passing a generated regex, which is what #4012 does. I'll leave this PR as the duplicate and let #4012 carry the change plus regression coverage.

onthebed avatar Apr 30 '26 01:04 onthebed