Skip to content

fix: quote SET dp0 in cmd shims to support paths with shell metacharacters - #189

Open
ashrafiucse wants to merge 1 commit into
npm:mainfrom
ashrafiucse:fix-quote-set-dp0
Open

ashrafiucse wants to merge 1 commit into
npm:mainfrom
ashrafiucse:fix-quote-set-dp0

Conversation

@ashrafiucse

Copy link
Copy Markdown

Fixes #45

What

The .cmd shims generated by cmd-shim set the batch file's directory with an unquoted SET:

SET dp0=%~dp0

When the shim lives in a path containing cmd.exe metacharacters (e.g. C:\test(n&pm)\ or ...\Playwright & API\...), the shell parses the & as a command separator. Two very confusing failures follow:

  • 'API\...\node_modules\.bin\' is not recognized as an internal or external command — cmd tries to execute the part of the path after the &
  • Cannot find module 'C:\...\Playwright Learn\@playwright\test\cli.js'dp0 got truncated right before the &, so the target resolves against the wrong base directory

This quotes the assignment using the standard safe idiom, which is already used for _prog in the same file:

SET "dp0=%~dp0"

Notes

  • Covers &, ^, ( and ) in paths. A literal % in the path remains unfixable in batch syntax.
  • Added a Windows-only functional test that creates a shim inside a dir & name folder and executes it through cmd.exe. Existing tests only snapshot the generated files, which is why a content-level regression like this could go unnoticed.
  • Snapshots updated.
  • This is a resubmission of fix #45 set command quoted #53, which was closed as stale.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] *.CMD shims don't work when they are in paths containing shell metachars

1 participant