Skip to content

completions of [validateset] parameters fails to escape special characters #10218

Closed

Description

@msftrncs

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 `$` escaped

Expected 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

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Jul 24, 2019
  2. added a commit that references this issue on Jul 24, 2019
    397988b
  3. msftrncs commented on Jul 27, 2019

    @msftrncs
    ContributorAuthor

    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.

  4. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    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.

  5. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    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.

  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    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.

  7. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions