New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter parsing/passing: an unquoted argument that looks like a named parameter/value pair separated with ":" (colon) is broken in two in positional binding #6292
Comments
Hi @mklement0 - this is actually by design. A ':' indicates the end of the parameter name and it doesn't need to be the last character in the string. If it's in the middle of the string, everything after the ':' is treated as the argument to that parameter. Handling parameters this way parallels how a lot of Windows command line tools parse their arguments. |
Understood, but that applies to named binding: if By contrast, in anonymous binding I would expect a token such as Note that the problem only arises with PowerShell functions, not with external programs: with the latter, commendably, I don't know enough about PowerShell's parameter binding to assess whether the distinction I'm asking for presents a conceptual / technical challenge. |
At the parser level, the parameter token ends with So from that point of view, this is easily explained and consistent. There is of course the issue with native commands - there was some effort to not add a space between the arguments when that space did not appear in the original script. There is a small problem with the current approach though - splatting to a native command will unfortunately add a space: function e1 { echoargs.exe @args }
echoargs.exe -a:b
e1 -a:b This outputs:
I suppose this is actually an independent bug, though changing behavior here would address the splatting issue as well (though it's not necessarily a good idea to change both - fixing splatting could be sufficient.) |
Thanks for the background information, @lzybkr.
Understood, but my point is that, purely from a conceptual perspective, something that isn't a named argument - even though it may look like one - should be passed through as-is - irrespective of whether it is passed to an external program or to a PowerShell cmdlet/function/script. The current behavior is inconsistent in that the token is parsed as a named argument - and altered in the process - yet ultimately passed as an unnamed one or, rather, two unnamed ones - and that's the problem. Of course, a simple workaround is to quote the argument: I've created a separate issue for the splatting bug: #6360 |
@mklement0 To be clear, parameters and arguments are only parsed once when the script is compiled. The command to run is not involved in parsing at all. Command resolution and parameter binding are separate steps done each time a command is executed, potentially long after the parse was completed. So, from the language perspective, |
@BrucePay: Thanks for this succinct peek behind the scenes and the pointer to the source code - much appreciated. Based on #6360, as diagnosed by @lzybkr, we now know that the limited "hack" needs fixing for In the interest of a consistent user experience, my plea is to take this opportunity to apply the same "hack" to (directly or splatted) arguments passed to cmdlets/ functions too:
Something that - even though later, for technical reasons - turns out not to be a parameter, can be dealt with consistently only in one of two ways:
If you ultimately don't know what a token such as I've updated the initial post to reflect the current state of our discussion. |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
1 similar comment
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes. |
Related: #6291 and #6360
Note: Unlike the linked issues, the broken behavior described here only affects PowerShell commands, not also native executables.
Steps to reproduce
Expected behavior
Actual behavior
That is, the single $Args /
ValueFromRemainingArguments
-bound argument was unexpectedly broken in two.Note that, by contrast, the following cases DO work correctly:
When passing tokens such as
-foo:bar
to external programs - because special effort is already being expended to make this case work (which is needed, because initially all such tokens are parsed as if they were named parameters, even if they later turn out not to be - see @BrucePay's comment below.)$Args
or@Args
, the breaking-in-two problem surfaces too - see 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 #6360Had there been a named parameter
$foo
to bind to, things would have worked as expected (the token would have been recognized as a parameter-name/value pair: the-foo
part would have been used to identify the target parameter, and thebar
part would have become the parameter variable's value).Environment data
The text was updated successfully, but these errors were encountered: