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
    Needs-Triage
    on Apr 19, 2021
  2. added
    WG-Engine
    on Apr 20, 2021
  3. added
    Issue-Bug
    and removed
    Needs-Triage
    on Jun 9, 2021
  4. ghost added
    In-PR
    on Jul 19, 2022
  5. ghost removed
    In-PR
    on Jul 19, 2022
  6. ghost added
    Resolution-Fixed
    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-BugResolution-FixedWG-Engine

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions