Skip to content

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

Closed

Description

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

Activity

  1. changed the title [-]Experimental feature PSNativeCommandArgumentPassing doesn't support with embedded double quotes when calling batch files[/-] [+]Experimental feature PSNativeCommandArgumentPassing doesn't support arguments with embedded double quotes when calling batch files[/+] on Apr 16, 2021
  2. SteveL-MSFT commented on Apr 18, 2021

    @SteveL-MSFT
    Member

    The proposed fix would be to special case cmd.exe and files ending with .bat or .cmd to pass enclosed double quotes as ""?

  3. mklement0 commented on Apr 18, 2021

    @mklement0
    ContributorAuthor

    Indeed, Steve Lee (@SteveL-MSFT).

    It is part of what I've been proposing for months, repeatedly, in conversations you were a part of: here and here and here, which finally evolved into a - hopefully comprehensive and final - proposal in #15143, which summarizes all accommodations that I think are vital to make on Windows, the need to escape " as "" for batch files being just one of them.

    Excuse me for shouting, but it's out of desperation over these issues seemingly never being paid proper attention to; this isn't a personal concern; rather, I think these issues are of vital importance for all PowerShell users, and we should finally get them right.

    Therefore, I ask you to please take the time to fully understand and discuss:


    Moved to #15143 (comment)

  4. mklement0 commented on Apr 19, 2021

    @mklement0
    ContributorAuthor

    Steve Lee (@SteveL-MSFT), I've moved the gist of my previous comment to #15143 (comment), to have all the relevant information in one place.

    Note that a new bug has since joined the ranks: #15276

  5. added
    Issue-BugIssue has been identified as a bug in the product
    and removed
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Jun 9, 2021
  6. seanbudd commented on Jun 26, 2023

    @seanbudd

    Any updates on this bug?

  7. seanbudd commented on Dec 24, 2023

    @seanbudd

    Bump to keep open

  8. seanbudd commented on Jun 22, 2024

    @seanbudd

    Bump to keep open

  9. microsoft-github-policy-service commented on Dec 19, 2024

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

  10. brian6932 commented on Dec 26, 2024

    @brian6932

    This is still an issue, any maintainers around to reopen?

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

Metadata

Metadata

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