You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
variable tab completion does not escape curly quotes, potentially others #10006
Similar to #9881, while attempting to tab complete a variable reference, at least curly quotes (I've also determined en-dash/em-dash too) do not cause an escape to the ${ } notation.
Steps to reproduce
${test`u{2018}var} ='Hello World'$t# press tab for completion until `test‘var` appears
I think this is inadequate to catch the conditions that require when the ${ } notation is needed, but the above constant appears to be used for more than just that. The list of characters that require the ${ } notation is much larger and more complicated. If regex could be used, the following might be more accurate for when to require the ${ } : ^(?:[^$^\w?:]|[$^?].)|.(?:::|[^\w?:]) This would return a MATCH when ${ } is required. Examples:
This is actually further complicated, because the variables $$, $^, $! etc are all special. They should require braces, but the tokenizer explicitly allows them as special variables.
I've also found that there are some issues around variables that contain : (I know there are some opinions there), but demonstrating a more complete escaper:
filtervariableNotate {
param(
[string]$ScopeOrProviderPrefix=''# specify either scope or provider prefix
)
# return a result object similar to the System.Management.Automation.CompletionResult class
[pscustomobject]@{
ListItemText=$_CompletionText="$($(if ($ScopeOrProviderPrefix-eq'') {# no scope/drive prefix, detect reasons to force a blank prefixif ($_.Contains([char]':') -or$_-match'^\?[\w?:]+$') {# force `:` prefix for names containing `:` or beginning with `?` but not needing `{}`":$_" } else {#no prefixing needed$_ } } else {# assemble the prefixed completion"${ScopeOrProviderPrefix}:$_" } ).foreach{# detect if final completion requires `{}`if ($_-match'^(?:[^$^\w?:]|[$^?].)|.(?:::|[^\w?:])') {# `{}` required, escape where needed"{$($_-replace'[{}`]','`$0')}" } else {# no wrapping or escaping needed$_ } })"
}
}
This filter now produces an output similar to the CompletionResult class.
While writing this up, I also found that the *Hello variable doesn't complete correctly, * is also missing from the list of characters that require escape, but you can see this filter suggests the correct completion.
Edit: Revised filter a few times to optimize the regex, and better capture condition of variables starting with '?', Reference the ?? variable in the sample output.
I have an intention to post a PR regarding at least parts of this issue, implementing the escapers already found in the CodeGeneration class, and we'll see how far I can go from there.
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 commented on 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 commented on 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.
Activity
msftrncs commentedon Jun 26, 2019
Also, slightly related,
${test`{`}} = 'Hello World' $t # press tab for completion until `{test{}}` appearsExpected
${test`{`}}Actual
${test{}}This will cause an error stating that you must use
`{instead of{in variable names.vexx32 commentedon Jun 26, 2019
This is actually further complicated, because the variables
$$,$^,$!etc are all special. They should require braces, but the tokenizer explicitly allows them as special variables.msftrncs commentedon Jun 26, 2019
Never heard of
$!. The regex above was set to handle the fact that the tokenizer accepts those special conditions.msftrncs commentedon Jun 26, 2019
I think I might have missed
$?… EDIT: I corrected the above regex for the special condition of$?msftrncs commentedon Jun 26, 2019
Also adding that
$??fails to be completed correctly as${??}, as I noticed?was not in the constant list of characters in the code referenced.Edit:
$:??is also acceptable.msftrncs commentedon Jun 26, 2019
Sample PowerShell filter code for testing:
Note that a more complete filter might escape all control characters, such that <TAB> (^I) would become
`tand so on.Edit: missed
`in the list of characters that need escaped in the-replaceoperation.Edit: improved performance of the
-matchregexmsftrncs commentedon Jul 1, 2019
Also adding that variables with backticks in their name will properly wrap with
${ }when completed but fail to escape the backtick in that notation.msftrncs commentedon Jul 20, 2019
I've also found that there are some issues around variables that contain
:(I know there are some opinions there), but demonstrating a more complete escaper:This filter now produces an output similar to the CompletionResult class.
Example usages: (uses aliases)
Both above should demonstrate the correct escaped completion to use with the
$sigil.(Partial Output from
env:*)(Partial Output from
variable:*)While writing this up, I also found that the
*Hellovariable doesn't complete correctly,*is also missing from the list of characters that require escape, but you can see this filter suggests the correct completion.Edit: Revised filter a few times to optimize the regex, and better capture condition of variables starting with '?', Reference the
??variable in the sample output.msftrncs commentedon Jul 21, 2019
I have an intention to post a PR regarding at least parts of this issue, implementing the escapers already found in the
CodeGenerationclass, and we'll see how far I can go from there.implementing GenerateVariableCompletionText
msftrncs commentedon Jul 22, 2019
I was able to implement a C# version of my PowerShell filter,
https://github.com/msftrncs/PowerShell/blob/0af1d06de68391d04f77c3efd3db58a8bd23a036/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs#L4804-L4843
Where does this best belong?
improve variable name competion results
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.