Title: completions of [validateset] parameters fails to escape special characters · Issue #10218 · PowerShell/PowerShell · GitHub
Open Graph Title: completions of [validateset] parameters fails to escape special characters · Issue #10218 · PowerShell/PowerShell
X Title: completions of [validateset] parameters fails to escape special characters · Issue #10218 · PowerShell/PowerShell
Description: Steps to reproduce function test ([validateset('$test', 'test$', 'test test', '#', '# hello', '#requires more', '<# hello #>')]$test) {echo $test} test
Open Graph Description: Steps to reproduce function test ([validateset('$test', 'test$', 'test test', '#', '# hello', '#requires more', '<# hello #>')]$test) {echo $test} test
X Description: Steps to reproduce function test ([validateset('$test', 'test$', 'test test', '#', '# hello', '#requires more', '<# hello #>')]$test) {...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/10218
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"completions of [validateset] parameters fails to escape special characters","articleBody":"# Steps to reproduce\r\n\r\n```powershell\r\nfunction test ([validateset('$test', 'test$', 'test test', '#', '# hello', '#requires more', '\u003c# hello #\u003e')]$test) {echo $test}\r\n\r\ntest \u003cALT-SPACE\u003e # value `$test` will not be escaped or quoted due to `$`, nor will the completions that start with `#`, except `#requires more` gets quoted\r\n# also, `\u003c# hello #\u003e` fails to be quoted\r\ntest \"\u003cALT-SPAC\u003e\" # values `$test` and `test$` will not have the `$` escaped\r\n```\r\n\r\n# Expected behavior\r\n\r\nAll special characters (those affecting tokenizing the argument correct intentions) would force quoting or escaping. \r\n\r\n# Actual behavior\r\n\r\nSome characters do, some do not. \r\n\r\nThis 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 `#`\r\n\r\nI 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.\r\n\r\n# Environment data\r\n\r\nPowerShell 7.0.0-preview.2\r\n\r\n# Considerations\r\n\r\nThis 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.\r\n","author":{"url":"https://github.com/msftrncs","@type":"Person","name":"msftrncs"},"datePublished":"2019-07-24T01:31:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/10218/PowerShell/issues/10218"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e71b393b-e1ae-3ccc-3b88-e2f900587513 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B25C:1A0C43:32055:46807:6A5A3F71 |
| html-safe-nonce | 3fa4192f40757a6bddc3908a6a850c0e5b5470df8c8de403de51b3e09552cd23 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjVDOjFBMEM0MzozMjA1NTo0NjgwNzo2QTVBM0Y3MSIsInZpc2l0b3JfaWQiOiI0MDc1MjMxMDg4Njc5MjA2NzY5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cadf2242b0067f7f34fb30c078e5f684d3fa174b4c178b63724bfd3777a7a853 |
| hovercard-subject-tag | issue:472036826 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/10218/issue_layout |
| twitter:image | https://opengraph.githubassets.com/379b20d66aee39064470bbed2a661f570c24cab9068d9be6453879ddcc654988/PowerShell/PowerShell/issues/10218 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/379b20d66aee39064470bbed2a661f570c24cab9068d9be6453879ddcc654988/PowerShell/PowerShell/issues/10218 |
| og:image:alt | Steps to reproduce function test ([validateset('$test', 'test$', 'test test', '#', '# hello', '#requires more', '<# hello #>')]$test) {echo $test} test |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | msftrncs |
| hostname | github.com |
| expected-hostname | github.com |
| None | 19c67ad7579d2401ff06e88a32ef45460fbb40fab3191c7f7582d5e166f326fc |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e618485bff22dab2ef1ffb4e34e4e6626688df69 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width