Skip to content

Experimental feature PSNativeCommandArgumentPassing doesn't support arguments with embedded double quotes when calling batch files #15250

@mklement0

Description

@mklement0

Similar to #15239, this issue would be resolved by the proposal in #15143. See also: #15261 and #15276

Note that high-profile CLIs such as az and npm (Node.js's package manager), for script-based utilities that come with packages, use batch files as their entry points.

Steps to reproduce

Run the following on Windows:

# Switch to a temporary directory.
Push-Location -ea Stop ($tmpDir = (New-Item -Type Directory -Force (Join-Path Temp:/ $PID)).FullName)

# Create a batch file that strips enclosing double quotes from the first argument and deduplicates the 
# embedded ones.
@'
@echo off & setlocal
set Arg1=%~1
echo [%Arg1:""="%] [%2]
'@ > foo.cmd

./foo.cmd 'Andre "The Hawk" Dawson' | Should -Be '[Andre "The Hawk" Dawson] []'

# Clean up.
Pop-Location; Remove-Item $tmpDir -Recurse

Expected behavior

The test should succeed.

Actual behavior

The test fails, because the argument with embedded " isn't passed batch-file-appropriately - batch files (cmd.exe) do not recognize \" as an escaped " and require "" instead:

InvalidResult: Expected strings to be the same, but they were different. 
Expected length: 28 Actual length:   30 Strings differ at index 7. 
Expected: '[Andre "The Hawk" Dawson] []' 
But was:  '[Andre \"The] [Hawk\" Dawson"]'

Note the literally retained \ and the unexpected breakup into two arguments.

For this invocation to succeed it would have to pass verbatim Andre "The Hawk" Dawson as "Andre ""The Hawk"" Dawson" - i.e. escaping the embedded " as "" rather than \" - on the command line used behind the scenes.

Environment data

PowerShell Core 7.2.0-preview.5 on Windows

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions