Repository navigation
WIP: Incorrect arg splitting when using .. syntax for git log - #20091
James Truher (JamesWTruher) wants to merge 13 commits into
Conversation
3fc64a7 to
41d8cf7
Compare
a1ba43e to
eef18ed
Compare
eef18ed to
4470b6e
Compare
4bf6b3b to
7c4961e
Compare
There was a problem hiding this comment.
By setting sawColonAtEnd = true here, the resulted ParameterToken will have the public property UsedColon set to true, which is incorrect for this publicly exposed API.
## an example output of the ParameterToken
ParameterName : foo=
UsedColon : True
Text : -foo=
TokenFlags : None
Kind : Parameter
HasError : False
Extent : -foo=
There was a problem hiding this comment.
Also, the code here doesn't consider InCommandMode() as it does in the default branch, which will result in different tokens when -f= is tokenized in the expression mode. But this is less concerned than the incorrect value for the public property UseColon.
There was a problem hiding this comment.
This also seems to change how ValueFromRemainingArguments works with strings. For example:
echo -d=testWould previously return a single string of -d=test but now returns
-d=
test
This would be most impactful for commands that wrap native commands.
function Show-PowerShellWithBat {
param(
[Parameter()]
[string] $Script,
[Parameter(ValueFromRemainingArguments)]
[string[]] $AdditionalArguments
)
end {
$Script | bat --language powershell @AdditionalArguments
}
}
Show-PowerShellWithBat '$testing' -r=1That will cause bat to emit
[bat error]: Empty line range
due to the extra space
There was a problem hiding this comment.
Dongbo Wang (@daxian-dbw) Patrick Meinecke (@SeeminglyScience) thanks - I was trying to treat HasColon as a behavioral "no space between parameter and argument" (which likely wouldn't have considered = when it was created) rather than adding a new property. More disturbing to me is the ValidateFromRemainingArguments concern because it wasn't caught by our current validation. I'll certainly be adding that as a test (or 4) when this is ready.
all of my earlier attempts (without the parser change) couldn't handle the -foo=${a}..b case which is why i went down this path. I think I'll have to not have the parser change and handle it only in the native parameter binder which should still handle the original issue of git diff $a..$b . Without the parser change, it's likely to not even be a breaking change, and you must still use "-foo=${a}..bar" to get that into the native app.
back to the drawing board - marking this back to WIP
There was a problem hiding this comment.
I found a different way to do this with Patrick Meinecke (@SeeminglyScience), so I've removed the work in progress. The new solution works with the bat example as desired (solving the ValueFromRemainingArguments mishandling). Essentially, now when we see an = as part of a parameter, we re-parse the input as a generic token rather than a parameter. This will certainly work better for native applications.
I also added some additional tests for ValueFromRemainingArguments to be a little more exotic.
a09ac50 to
dd418a2
Compare
dd418a2 to
6e5a046
Compare
e998d2f to
2920dc8
Compare
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
@PowerShell/powershell-committee discussed this and agree with the new behavior regarding
Overall, although a breaking change, we believe this is bucket 3 and improves the command-line experience overall so worth taking. |
2920dc8 to
606d525
Compare
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
Cleanup is still needed.
Not refactoring the BindParameters method even though codefactor says it's too complex.
…Binder.cs Co-authored-by: Steve Lee <slee@microsoft.com>
…Binder.cs Co-authored-by: Steve Lee <slee@microsoft.com>
Improve new tests for native arguments.
Add additional tests for ValueFromRemainingArguments attribute.
606d525 to
484e969
Compare
PR Summary
Fix #15279
PR Context
The current NativeParameterBinder (NPB) receives 2 distinct parameters from the parser which need to be combined, but does not as the following example shows:
While investigating this, i discovered other behavior which makes it difficult to interact with native executables. There are native applications which allow parameters to be expressed as
-parm=valuewhich can be very useful if you can use variables:-param=${param}.Unfortunately, this is currently converted to:
The parser recognizes the
-foo=$as the parameter because of the opening brace, and then the minish treatment converts the second argument (which looks like a scriptblock) to a base64 encoded string. After this minishell conversion the NPB is called with these newly constructed parameters.There is a work-around: using double quotes
"-foo=${thing}"will properly pass the argument to the NPB, but this is somewhat difficult to discover after the case because the behavior is so unexpected and in most cases, the error just looks like you've used the command incorrectly.The change does two things:
=similarly to:(but retains the=as a part of the parameter)There is a breaking behavior here:
Currently, it is possible to support parameters (in scripts, not in compiled code) which look like
param (${z=p}).for the function
function zap { param (${p=z}); "p=z:" + ${p=z}; "args: " + $args }, the current behavior isThe new behavior is:
the parameter is bound positionally rather than by the parameter name because
-p=zis no longer recognized as a parameter, but an argument. Although I do not believe that this change will affect many (if any) current pwsh users.Because e now re-parse a parameter with an
=as an argument rather than parameter is the reason that the behavior when using a:is now:the entire
-p=z:arg!string is seen as a non-positional argument and is bound to thep=zparameter.We can see this by inspecting the ASTs as follows:
Present:
and new:
This PR behavior is accessible by enabling the
PSNativeParameterParsingExperimental feature.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).