PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

& operator launches commands differently in 7.3.0

Open wasker opened this issue 3 years ago • 6 comments

Prerequisites

Steps to reproduce

Program.cs.txt test.ps1.txt

  1. Build C# app called blah.exe using Program.cs, make sure it's on the path.
  2. Run pwsh -f test.ps1 and observe the output.

Expected behavior

On 7.2.7:

Something will happen: working...
Something will happen: done.
--set
deployment.environment=blah
--set
deployment.region=blah
--set
deployment.image.repository=blah

Actual behavior

On 7.3.0:

Something will happen: working...
Something will happen: done.
--set
deployment.environment="blah"
--set
deployment.region="blah"
--set
deployment.image.repository="blah"

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.19044
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

wasker avatar Nov 15 '22 21:11 wasker

This is ultimately a duplicate of #18554, but let me add some context:

  • v7.3.0 introduced a breaking change with respect to how arguments with embedded " characters as well as empty-string arguments are passed to external programs: a longstanding bug was fixed, fully on Unix, partially on Windows.

    • Update: It looks like this breaking change may get reverted in some version after v7.3.1 so as to make it opt-in rather than opt-out, but on Windows only - see #18694
  • Existing workarounds that build on the old, broken behavior now break - except in calls to batch files and WSH scripts, where the legacy workarounds will continue to work by default.

  • The fixed behavior now correctly escapes embedded " characters as \" on the process command line PowerShell constructs behind the scenes, which is the most widely observed convention on Windows, and also supports passing empty strings as arguments.

    • Thus, an argument such as "deployment.environment=`"blah`"", which from PowerShell's perspective has a verbatim value of deployment.environment="blah" is now placed as follows on the target process' command line: "deployment.environment=\"blah\"", and if the target process observes the aforementioned convention, it ends up parsing that again as verbatim deployment.environment="blah", which is what you saw.

There's additional background information in this Stack Overflow answer.

mklement0 avatar Nov 15 '22 21:11 mklement0

Thank you for the links!

There's no mention of this behavior change in relnotes for 7.3.0 - https://github.com/PowerShell/PowerShell/releases/tag/v7.3.0

GitHub
Release v7.3.0 Release of PowerShell · PowerShell/PowerShell
7.3.0 - 2022-11-08 General Cmdlet Updates and Fixes

Correct calling cmdlet New-PSSessionOption in script for Restart-Computer (#18374)

Tests

Add test for framework dependent package in release p...

wasker avatar Nov 15 '22 22:11 wasker

My pleasure, @wasker.

There's no mention of this behavior change in relnotes for 7.3.0 -https://github.com/PowerShell/PowerShell/releases/tag/v7.3.0

That GitHub link doesn't provide a cumulative view of what changed in that release - it just shows whatever changed in the final commit that led to the release.

  • While you could infer the cumulative changes from https://github.com/PowerShell/PowerShell/releases, the official what's-new summary for a given release should be at https://learn.microsoft.com/en-us/powershell/scripting/whats-new/overview

  • However, as of this writing, https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-73 does not contain the relevant information.

  • The PowerShell Team blog at https://devblogs.microsoft.com/powershell/powershell-7-3-general-availability/ at least mentions the feature that caused the breaking change, but, to my mind, that description is inadequate, given that the fact that it is breaking isn't even mentioned.

    • As an aside: The post also suggests that the experimental PSNativeCommandErrorActionPreference was made stable, but from what I can tell that isn't actually the case.
GitHub
Release v7.3.0 Release of PowerShell · PowerShell/PowerShell
7.3.0 - 2022-11-08 General Cmdlet Updates and Fixes

Correct calling cmdlet New-PSSessionOption in script for Restart-Computer (#18374)

Tests

Add test for framework dependent package in release p...

GitHub
Releases · PowerShell/PowerShell
PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
A collection of release notes and documentation about the new features available in new versions of PowerShell.
New features and changes released in PowerShell 7.3
PowerShell Team
General availability of PowerShell 7.3

mklement0 avatar Nov 15 '22 23:11 mklement0

cc @michaeltlombardi

The content team should have plans to have an about topic specifically around using native commands in PS7 and I expect will capture these types of details

SteveL-MSFT avatar Nov 16 '22 01:11 SteveL-MSFT

See also:

  • https://github.com/MicrosoftDocs/PowerShell-Docs/issues/5152

mklement0 avatar Nov 16 '22 02:11 mklement0

@SteveL-MSFT - given that this is the second report of this issue in as many days, I wonder if it might be wiser for the default value of $PSNativeCommandArgumentPassing to be legacy. ? I think (as @mklement0 says) the previous behaviour was a bug, but one which so many had lived with for so long it became "standard" - I put this as an open question because what gives the best gain:pain ratio is not obvious to me :-)

Some of the 7.3 changes (PSReadline prediction being on, colouring directories, formatting of floating point in tables, the change to convertFrom-Json -as hash table, and this one) need to publicized more than they have been , the community can help on that but docs and team blog probably need to to take the lead. I'm for 3/5 of those, against 1/5, and this one I'm not sure about. Not all changes are bad, but surprises generally are, especially if the explanation is hard to find.

jhoneill avatar Nov 16 '22 09:11 jhoneill

This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.

ghost avatar Nov 17 '22 12:11 ghost