Skip to content

Docs: say what cmd.exe's delayed expansion does to a quoted argument - #130

Merged
HalRiveria merged 5 commits into
mainfrom
docs/cmd-delayed-expansion
Dec 3, 2026
Merged

HalRiveria merged 5 commits into
mainfrom
docs/cmd-delayed-expansion

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

Depends on #128, merge after it.

What was missing

The README's "What quoting can't stop" for cmd.exe and batch files named %NAME% and =, but not delayed expansion. With it on, cmd.exe also expands !NAME! inside a quoted argument, and the kit's quoting can't stop that.

What changed

The README's batch-file paragraph and ConvertTo-PkArgumentString's help comment now say what delayed expansion does to a quoted argument:

  • !NAME! is expanded inside quotes;
  • a ^ in an argument that holds a ! is dropped;
  • in a batch file, an unset !NAME! or a lone ! is dropped as well.

The README names the three ways delayed expansion gets turned on.

How it was checked

On Windows PowerShell 5.1 and PowerShell 7, through Invoke-PkProcessBatch with list arguments:

Program Argument Result
cmd /d /v:on /c echo a^b! "ab!"
cmd /d /v:on /c echo a^b "a^b"
cmd /d /v:on /c echo x!y x!y (a lone ! stays on cmd's own command line)
a .cmd with setlocal EnableDelayedExpansion and echo [%1] !PK_O17! [EXPANDED]
the same .cmd x!y [xy]
the same .cmd an unset !NAME! []

The registry setting wasn't tried, since it changes the machine's settings; the README points to cmd /? for it.

The full harness passes on 5.1 and 7 (803 assertions each), and Testing/readme-examples/run.ps1 passes.

HalRiveria and others added 5 commits December 3, 2026 09:08
…fer only in case

A case-sensitive [hashtable]::new() job with 'canceltoken' got the kit's own token in its place, since the check used the job's own comparer and the worker's copy is case-insensitive. Two keys differing only in case collapsed into one, the later silently winning; such a job is now refused, up front for -JobParams and as it arrives for -NextJobProvider.
When -MaxOutputChars' head would end on the first half of a surrogate pair, it turned that half away but the tail kept its own size, so output exactly as long as the cap lost the pair. The tail now takes the slot the head turns away.
The group-fetch loop tested only the token, which is cancelled after it, so an abort raised by -GroupProvider, -JobBuilder, -GroupCompleteCallback or -GroupReleaseCheck still asked -GroupProvider for more groups and built them, up to -MaxQueueAhead, or every group when they had no jobs.
@HalRiveria
HalRiveria merged commit 4b09e95 into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the docs/cmd-delayed-expansion branch December 3, 2026 16:12
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