- Notifications
You must be signed in to change notification settings - Fork8.1k
AddQuoteCompletionText method to CompletionHelpers class#25180
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
AddQuoteCompletionText method to CompletionHelpers class#25180
Uh oh!
There was an error while loading.Please reload this page.
Conversation
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Thanks for feedback@iSazonov. I have made method more flexible with different escaping parameters, a lot of code in CompletionCompleters can use new method. Mostly the simple blocks where single quote escaping was happening before quoting. I've also added XUnit tests for the QuoteCompletionText method. |
Can we use it in GetMatchingResults() method for other completers? |
@iSazonov It is used in PowerShell/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs Line 41 in6ea3b85
|
Probably best to also wait on#25184 so existing implementation of |
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
…letionHelpers.csCo-authored-by: Ilya <darpa@yandex.ru>
I'll fix the tests. |
@MartinGC94 If you have time, it would be great to have a review. I have started writing a new method |
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
/azp run |
| Azure Pipelines successfully started running 1 pipeline(s). |
@ArmaanMcleod At a glance it looks fine to me for the intended purpose of removing all the duplicate code and escaping single quotes. |
@ArmaanMcleod Please look CI fails. |
Thanks@iSazonov for review and suggestions. I have added back in dynamic escaping for double quotes and updated tests. |
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| [InlineData("","'","''")] | ||
| [InlineData("","\"","\"\"")] | ||
| [InlineData("'","'","''''")] | ||
| [InlineData("","","''")] |
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 still think we should cover CompletionRequiresQuotes by tests too. There we use Parser and additionally checks for backtick and$.
So string for tests could be like "a b", "$a", "a" Maybe you could think more tests - I seeStringTokenandTokenFlags.Keyword` in the method. The test strings could be "a$a" and "while" accordingly with variants with backtick and $.
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.
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.
Thanks!
The QuoteCompletionText is more interesting for us. Maybe add 2-3 key tests here?
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.
Up!
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.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Ilya <darpa@yandex.ru>
| [InlineData("","'","''")] | ||
| [InlineData("","\"","\"\"")] | ||
| [InlineData("'","'","''''")] | ||
| [InlineData("","","''")] |
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.
Thanks!
The QuoteCompletionText is more interesting for us. Maybe add 2-3 key tests here?
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
…letionHelpers.csCo-authored-by: Ilya <darpa@yandex.ru>
Uh oh!
There was an error while loading.Please reload this page.
| [InlineData("word with space","'","'word with space'")] | ||
| [InlineData("word with space","\"","\"word with space\"")] | ||
| [InlineData("word\"with\"quotes","'","'word\"with\"quotes'")] | ||
| [InlineData("word'with'quotes","\"","\"word'with'quotes\"")] |
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'd add tests for "while", "$variable" and "key$word".
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.
@iSazonov I believe we have tests for those already?
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.
Or do we want the same test from CompletionRequiresQuotes in QuoteCompletionText?
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.
It looks like duplicate but it protects from regression if we will improve CompletionRequiresQuotes and change its tests.
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.
Yep makes sense, I have added tests in5cb39e0
Co-authored-by: Ilya <darpa@yandex.ru>
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
94d0361 intoPowerShell:masterUh oh!
There was an error while loading.Please reload this page.
microsoft-github-policy-servicebot commentedMar 22, 2025 • edited by unfurl-linksbot
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by unfurl-linksbot
Uh oh!
There was an error while loading.Please reload this page.
📣 Hey@ArmaanMcleod, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗https://aka.ms/PSRepoFeedback |
Uh oh!
There was an error while loading.Please reload this page.
PR Summary
Add
QuoteCompletionTextmethod to CompletionHelpers class.This is to ensure quoted completions also get escaping done before surrounding quotes are added. Current code in
GetMatchingResultsjust surrounds completion with quotes without doing any escaping.I've replaced this code as well as many single quote escaping calls in CompletionCompleters.
PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).