Skip to content

Experimental feature PSNativeCommandArgumentPassing breaks calls with parameter-like arguments that end in ":" (colon) #15276

Closed

Description

Related: #15239, #15250, #15261 - see overview in #15143.

A parameter-like argument (prefixed with -) that ends in : (colon) is unexpectedly merged with the following argument.

For instance, this can break awk calls on Unix that use -F: to specify : as the field separator - see steps below.

On Windows, the problem can be demonstrated thus:

PS> cmd /c echo -F: bar  # Simplest repro on Unix: /bin/echo -F: bar
-F:bar  # !! Missing space between '-F:' and 'bar'

Note: In PowerShell parameter binding, -Foo: bar and -Foo:bar are equivalent, but this isn't appropriate when calling external programs.

Steps to reproduce

Run on Linux or macOS (but the problem also affects Windows), with PSNativeCommandArgumentPassing in effect (and preference variable $PSNativeCommandArgumentPassing set to 'Standard'):

# Run an awk command that extracts the usernames from /etc/passwd
$sb = { cat /etc/passwd | awk -F: '{print $1 }'  | Should -Not -BeNullOrEmpty }

# In legacy mode, the command succeeds
& { $PSNativeCommandArgumentPassing = 'Legacy'; & $sb }

# In standard mode (the new mode enable with the experimental feature), the command breaks:
& $sb

Expected behavior

Both tests should pass.

Actual behavior

The second test fails, because distinct arguments -F: and '{print $1}' were unexpectedly merged into a single argument with verbatim content -F:{print $1}:

# ... awk error message / usage info, due to the command having become syntactically invalid.
InvalidResult: Expected a value, but got $null or empty.

Environment data

PowerShell Core 7.2.0-preview.5

Activity

  1. 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
  2. ghost added
    In-PRIndicates that a PR is out for the issue
    on Jul 19, 2022
  3. ghost removed
    In-PRIndicates that a PR is out for the issue
    on Jul 19, 2022
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-FixedThe issue is fixed.WG-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