Skip to content

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

@mklement0

Description

@mklement0

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

Metadata

Metadata

Assignees

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