fix: Don't escape regex characters in test commands on Windows
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()
Fix looks good. Can you sign the CLA please?
Thank you for the pull request. I think we should go with #4012 instead
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.
Friendly bump -- this PR has been open for a while. Happy to make any changes if needed, or close it if no longer relevant.
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.
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.
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.