Skip to content

In pwsh 7.3.0 the call operator escapes embedded quotes. #18756

@skyguy94

Description

@skyguy94

Prerequisites

Steps to reproduce

After upgrading to 7.3.0 from 7.2.7 I noticed that the string passed in via the call operator retrieved from Environment.CommandLine has escaped embedded quotes that were not part of the original string. This is only in 7.3.0 as pwsh 7.2.7 and earlier and powershell 5.1 do not do this. I came across the problem with a custom tool (that uses libstandard2.0 and .net 4.8 for the libraries and exe respectively) that takes in json like this:

$json = ConvertTo-Json @{
  'Argument1'                = $Argument2
  'Argument2'                = $Argument1
  ...
}

& $tool -AsJson $json

where $json normally contains:

{
  "Argument1": "SomeValue",
  "Argument2": "SomeOtherValue"
  ...
}

but when I output the contents of Environment.CommandLine from the tool with 7.3.0 it looks like this:

{
  \\"Argument1\\": \\"SomeValue\\",
  \\"Argument2\\": \\"SomeOtherValue\\"
  ...
}

If I use Start-Process instead of the call operator then the string is left alone:

Start-Process $tool.Path -ArgumentList "-AsJson $json" -NoNewWindow

I came across this issue #18660 which mentions After the breaking change in native command execution but I could not find details on that breaking change or its impact in the release notes: https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-73?view=powershell-7.3

Expected behavior

The string should be unmodified:

{
  "Argument1": "SomeValue",
  "Argument2": "SomeOtherValue"
  ...
}

Actual behavior

The string is escaped:

{
  \\"Argument1\\": \\"SomeValue\\",
  \\"Argument2\\": \\"SomeOtherValue\\"
  ...
}

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions