Skip to content

Parameter parsing/passing: unquoted tokens that look like named arguments with colon as the separator are broken in two when passed indirectly via $Args / @Args #6360

@mklement0

Description

@mklement0

Related: #6291, #6292, and #4624

Following up from #6292 (comment):

Note: The tokens in question, such as -foo:bar, look like named PowerShell arguments (and, behind the scenes, are initially always parsed as such - see @BrucePay's comment below), but should be passed through as-is (except for possibly expanding the string) when calling external programs.

Tokens that happen to look like -foo.bar suffer a similar fate (see #6291).

This already works as expected with direct argument passing (e.g.,
echoArgs -foo:bar passes -foo:bar as a single argument
), but not when passing $Args / splatting it (@Args).

Note: The problem is fundamental to the use of $Args / @Args and, while perhaps less common, also affects its use when calling PowerShell-native commands - see comment below.

Steps to reproduce

Run on macOS or Linux.

function baz {
  bash -c 'for a; do echo $a; done' - $Args   # note: same with @Args
}

baz -foo:bar
'---'
baz -foo.bar

Expected behavior

-foo:bar
---
-foo.bar

Actual behavior

-foo:
bar
---
-foo
.bar

The arguments are unexpectedly broken in two. See linked comment for background.

Environment data

PowerShell Core v6.0.1 on macOS 10.13.3
PowerShell Core v6.0.1 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.1 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions