Skip to content

Stop-parsing token is broken #18664

Description

@mklement0

Prerequisites

Steps to reproduce

This was previously reported in #15261, which was inappropriately closed as by-design.

The purpose of --% (which only makes sense on Windows) is to copy the remainder of the command line verbatim to the process command line constructed behind the scenes, so as to provide a way to explicitly control the double-quoting for target executables that have non-standard quoting requirements.

As such, it should not be affected by the effective value of $PSNativeCommandArgumentPassing

(Note: It is debatable how arguments that come before --% on a given command line should be handled; for backward compatibility I think it would make the most sense to process them as if 'Legacy' were in effect; in other words: --% would be an implicit, command-scoped opt-in to $PSNativeCommandArgumentPassing = 'Legacy').

However, as of v7.3.0 it is, and the behavior is broken by default (the only way to make it work again is with $PSNativeCommandArgumentPassing = 'Legacy', which should not be necessary).

# Preparation: Create an executable that echoes the raw command line, as `.\echoCmdLine.exe`
# Note: Must call via *Windows PowerShell*
powershell -NoProfile {
  Add-Type -OutputType ConsoleApplication -OutputAssembly ./echoCmdLine.exe -TypeDefinition @'
  using System;
  static class ConsoleApp {
    static int Main(string[] args) {
      Console.WriteLine(Environment.CommandLine);
      return 0;
    }
  }
'@
}

# Set $PSNativeCommandArgumentPassing  to something *other* than 'Legacy'
$PSNativeCommandArgumentPassing = 'Windows'  # (the default on Windows)

# Using --%, pass *verbatim* `/p:Category="CI,Nightly"` on the process command line.
./echoCmdLine --% /p:Category="CI,Nightly"

Expected behavior

"C:\Users\jdoe\echoCmdLine.exe"  /p:Category="CI,Nightly"

That is, the part of the original command line after --% should be copied as-is to the process command line.

That is how it has worked since v3 (when --% was introduced) and should continue to work, irrespective of the value of $PSNativeCommandArgumentPassing = 'Legacy', in both PowerShell editions.

Actual behavior

"C:\Users\jdoe\echoCmdLine.exe" "/p:Category=\"CI,Nightly\""

Note how the argument was inappropriately enclosed in "...", with embedded " escaped as \".

That is, the 'Standard' behavior was inappropriately used (although cmd.exe-style environment variables, e.g. %OS%, do still get expanded).

Error details

No response

Environment data

PowerShell Core 7.3.0 on Windows

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions