Skip to content

Splatting with arrays containing --%, the stop-parsing token, doesn't work if the array element containing that token happens to be [psobject]-wrapped #21260

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

Note:

# On Windows

function foo {
  $ownArg = $args[0]
  # Using Select-Object causes the problem, due to [psobject]-wrapping the elements.
  $passThruArgs = $args | Select-Object -Skip 1
  # To fix the problem, uncomment the next line.
  # $passThruArgs[0] = $passThruArgs[0].psobject.BaseObject
  cmd /c echo @passThruArgs
}

foo own --% pass these args through, even with broken syntax such as "a or b)

Expected behavior

pass these args through, even with broken syntax such as "a or b)

That is, --% in the array used for splatting should result in the space-concatenated, verbatim list of the remaining arguments to be copied verbatim to the process command line behind the scenes.

Actual behavior

--% "pass these args through, even with broken syntax such as "a or b)"

That is, due to the - invisible and usually inconsequential - [psobject] wrappers created by Select-Object, splatting didn't recognize --% as the stop-parsing token, unexpectedly causing it to be passed on as an argument itself, and the remaining arguments to be enclosed in "...".

Error details

No response

Environment data

PowerShell 7.5.0-preview.1

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions