Skip to content

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

Open
BillionClaw wants to merge 1 commit intoShopify:mainfrom
BillionClaw:clawoss/fix/windows-regex-escape
Open

fix: Don't escape regex characters in test commands on Windows#4007
BillionClaw wants to merge 1 commit intoShopify:mainfrom
BillionClaw:clawoss/fix/windows-regex-escape

Conversation

@BillionClaw
Copy link
Copy Markdown

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()

Shellwords.escape() is designed for Unix shells and incorrectly escapes
characters like `$` on Windows. This causes test commands to fail when
running tests in terminal on Windows because the regex pattern
`/\^TestClass#test_method\$/` becomes `/\^TestClass#test_method\\$/`.

On Windows, we skip Shellwords.escape() since Windows command line
parsing doesn't require the same escaping rules for regex patterns.

Fixes Shopify#3759
@BillionClaw BillionClaw requested a review from a team as a code owner March 15, 2026 21:08
@rafaelfranca rafaelfranca added server This pull request should be included in the server gem's release notes bugfix This PR will fix an existing bug labels Apr 7, 2026
@rafaelfranca
Copy link
Copy Markdown
Member

Fix looks good. Can you sign the CLA please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR will fix an existing bug cla-needed server This pull request should be included in the server gem's release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CodeLens Run Test In Terminal doesn't work (on Windows) due to incorrectly escaped Regex

2 participants