Repository navigation
Description
Steps to reproduce
function test ([validateset('$test', 'test$', 'test test', '#', '# hello', '#requires more', '<# hello #>')]$test) {echo $test}
test <ALT-SPACE> # value `$test` will not be escaped or quoted due to `$`, nor will the completions that start with `#`, except `#requires more` gets quoted
# also, `<# hello #>` fails to be quoted
test "<ALT-SPAC>" # values `$test` and `test$` will not have the `$` escapedExpected behavior
All special characters (those affecting tokenizing the argument correct intentions) would force quoting or escaping.
Actual behavior
Some characters do, some do not.
This is due to a reliance of using the parser (via CompletionRequiresQuotes() method) to determine if there is more than 1 token, or if the parser has an error parsing the tokens contained in the completion. In the case of $test the parser sees exactly the one successful token and no more. I've also determined the same is happening for #
I understand why the parser is being used, but I think the idea is flawed because the parser doesn't know the full context of the completion, and can be swayed, as I have done here with the $test argument value.
Environment data
PowerShell 7.0.0-preview.2
Considerations
This is partially related to other completion bugs I have been reporting. I'd like to consider writing a more specific helper function/method for handling argument completions that can correctly determine if an argument needs quoted, and/or (if already quoted) properly escaped, and would not rely directly on the parser. I have covered this idea in #9881, and I am working on converting the PowerShell code example to C#. Using this helper, all argument type completions will be funneled through a single method for proper quoting and escaping. This does mean that making tweaks to the parser that might affect how a completion needs to be quoted/escaped would require tweaking this helper as well.
Activity
Implement QuoteArgument for all argument completers
msftrncs commentedon Jul 27, 2019
Additionally, and this technically affects all argument completions but is more likely to occur in
ValidateSet, argument completion values that start with a dash and follow with a valid identifier start character, or are just dash dash (--) should be quoted or escaped, to prevent them being parsed as a parameter name.microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.