-
Notifications
You must be signed in to change notification settings - Fork 234
Fix Pester CodeLens run/debug by not quoting params/already quoted args #794
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
Conversation
Requires a corresponding PR in vscode-powershell. We should look this one over good as it has potential to break folks. I think the odds are low. Essentially we added the QuoteEscapString method because we get raw paths from VSCode when debugging the current file. Those paths are quoted because they may contain spaces and because we use single quotes, existing single quotes have to be doubled e.g C:\Don'tUseQuotesInPaths to 'C:\Don''tUseQuotesInPaths'. This unfortunately was always being invoked on args. Now we check if the arg is a parameter (starts with '-') or is already quoted. The thinking is if the users is specifying a quoted arg, it's on them to handle any necessary escaping. BTW is there another char that can act as the start of a parameter - like the longer dash - whatever that is called. Longer term, we need a better solution for how to handle paths from VSCode. Maybe we handle them there and eliminate the escaping logic in PSES?
Ran across another case where the path quote escaping it biting us. I tried to pass these two parameters to debug launch |
Can you expand on this? |
For some history, check out: Related issues: OK, I think this is the PR that broke the Pester CodeLens provider: The PR above changed to quote and escape every argument. I don't think we can do that. If I pass an argument of I'm not sure what the right answer is but I think we should avoid messing with the debug script args in PSES. That said, we have to see if we can avoid regression here: PowerShell/vscode-powershell#1400 |
Hmm, we might need to rethink a few things on the #765 - sorry I didn't catcht these during the review: On line 772 (RHS), we are automatically escaping the
So not only can you enter a command instead of a script, you can even supply parameters. Unless we want to change what is supported by the I think the original code failed with So should we try to fix them in this PR - to revise a bit the changes in #765. I "think" what I'm proposing is to not quote args passed via |
Yes, I see I was overzealous in #765. |
I think to make this work we're going to have to throw away whatever our existing contract was with people -- some people are going to have to be broken so that all things can work in some way. It sounds like we need to leave quoting/escaping up to people themselves. Maybe we can have a check method that fires a warning if it thinks an argument should be quoted but isn't. So:
|
@@ -305,12 +305,22 @@ protected void Stop() | |||
var sb = new StringBuilder(); | |||
for (int i = 0; i < launchParams.Args.Length; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote we replace all this logic with arguments = string.Join(launchParams.Args, " ")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
sb.Append(PowerShellContext.QuoteEscapeString(launchParams.Args[i])); | ||
if (i < launchParams.Args.Length - 1) | ||
string arg = launchParams.Args[i]; | ||
if (arg.StartsWith("-") || arg.StartsWith("'") || arg.StartsWith("\"")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you say @rkeithhill, there are several characters PowerShell accepts to begin a parameter.
Agreed and this applys to debug launch config It could be I'm one of the few folks (involved with the original design) what the We've gotten by for a long time with that code in |
100% agree. It makes So this means:
? Any other things we need to nail down? |
So this work - funky path in script with args:
|
Ok so I've been discussing this with @TylerLeonhardt all morning because we were trying to work out what the right design is here. I'll try to summarise here:
|
Do you think that will work @rkeithhill? Want to discuss everything properly with you so we've got all the bases covered |
Agreed on all the "not touching args" comments. RE the Note that command is a
Also note how the VSCode sample/mock debugger handles this field ( It simply uses I believe we should keep the cc @weinand Do you have any input on whether an extension needs to convert launch config file paths ( |
Yeah, that was my original inclination as well, to also pass the script path verbatim and rely on users to escape that path properly themselves. But I can also imagine sending it through as a URI mainly to simplify our API requirements. I don't feel strongly either way. The first seems more consistent but the second seems less likely to annoy people. In the first case, I'm wondering:
While I can see arguments for escaping, it's sort of what's gotten us into trouble so far. I feel like it would ideally behave like |
They shouldn't need to do that. The change that you made that had the biggest impact was to switch from doing this (literally what
to this:
This fixes a lot of funky path issues by simply single quoting the path instead of trying to escape all the various chars which we weren't doing before your PR. IIRC we only escaped The above covers the
BTW agreed 100% That is why this PR (in it's current state) does only one thing and only to the |
Ah, so having us do the escaping is helpful because it depends on which As usual, I'm in favour of taking as much of the magic out as possible, but if the above is the case, then it makes sense to promise to escape the path if necessary. Regex escaping still troubles me a bit, but I suppose we can cross that bridge if we need to later. |
I want to make sure we are not talking past one another. :-) I don't think we need to do any "escaping" per se WRT to the This is a really "low touch" approach and seems less dangerous - to me at least. The other thing to keep in mind is that is scenario only comes into play when we use
This means we don't do any regex escaping in this scenario. And this is very similar to what you get at the command line right? You type
In our case, we choose to dot source rather than use |
That all makes sense to me. The only part I want to really verify is:
If I have a script like When I was experimenting with different pathological script names for #765, I found that there wasn't a great mechanism for dot-sourcing such a script and that single quotes didn't do anything. I ended up opening PowerShell/PowerShell#7999 and PowerShell/PowerShell#7995 as a result. |
According to the Windows FileExplorer a path cannot have a But I'm updating my test path to be more abusive - including
Just to re-iterate I'm not suggesting this particular change for anywhere else - just in this case where we are dot sourcing the user's script. That |
I think on Unix a * is valid. Not sure if that changes anything. |
Yeah |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @rkeithhill! Thank you for addressing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Requires a corresponding PR in vscode-powershell.
We should look this one over good as it has potential to break folks.
I think the odds are low. Essentially we added the QuoteEscapString
method because we get raw paths from VSCode when debugging
the current file. Those paths are quoted because they may contain
spaces and because we use single quotes, existing single quotes
have to be doubled e.g C:\Don'tUseQuotesInPaths to
'C:\Don''tUseQuotesInPaths'.
This unfortunately was always being invoked on args. Now we
check if the arg is a parameter (starts with '-') or is already quoted. The thinking is if the users is specifying a quoted arg, it's on them
to handle any necessary escaping.
BTW is there another char that can act as the start of a parameter -
like the longer dash - whatever that is called.
Longer term, we need a better solution for how to handle paths
from VSCode. Maybe we handle them there and eliminate the
escaping logic in PSES?