Skip to content

fix: turn off delayed expansion when running through cmd.exe - #198

Merged
43081j merged 2 commits into
tinylibs:mainfrom
monosans:fix/cmd-delayed-expansion
Nov 29, 2026
Merged

43081j merged 2 commits into
tinylibs:mainfrom
monosans:fix/cmd-delayed-expansion

Conversation

@monosans

Copy link
Copy Markdown
Contributor

When a command goes through cmd.exe on Windows, it runs as cmd.exe /d /s /c "...". /d keeps the registry's AutoRun commands out, but delayed expansion can also be turned on in the registry (HKCU\Software\Microsoft\Command Processor\DelayedExpansion). When it is, cmd.exe expands !name! in the arguments, and the caret escaping doesn't stop it, since ^ is removed before delayed expansion runs. So x('tool.cmd', ['a!PATH!b']) passes the value of PATH to the script instead of the literal text.

Fix

Pass /v:off. Command line switches take precedence over the registry, so arguments come through the same way on every machine. execa passes /v:off too.

Testing

Windows 11 24H2 (26100), Node 26.13.1.

  • To see the bug without touching my registry, I ran the args normalizeSpawnCommand builds for echo_args.cmd with a!PATH!b, adding /v:on (what the registry setting switches on). The script got my PATH expanded into the argument. Without delayed expansion it got a!PATH!b.
  • I updated the existing expectations to include /v:off.
  • tsc --noEmit, eslint and prettier pass.
  • vitest: everything passes except 5 tests in main_test.ts that compare cmd.exe's English "is not recognized" message. My Windows is in Russian, so they fail the same way on main.

@43081j
43081j merged commit 84d410a into tinylibs:main Nov 29, 2026
13 checks passed
@monosans
monosans deleted the fix/cmd-delayed-expansion branch November 30, 2026 23:21
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.

2 participants