-
Notifications
You must be signed in to change notification settings - Fork 8k
Add QuoteCompletionText
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add QuoteCompletionText
method to CompletionHelpers class
#25180
Conversation
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
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 in 6ea3b85
|
Probably best to also wait on #25184 so existing implementation of |
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs
Outdated
Show resolved
Hide resolved
…letionHelpers.cs Co-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
Outdated
Show resolved
Hide resolved
/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
Outdated
Show resolved
Hide resolved
[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 see
StringTokenand
TokenFlags.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.
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
Outdated
Show resolved
Hide resolved
…letionHelpers.cs Co-authored-by: Ilya <darpa@yandex.ru>
[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 in 5cb39e0
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.
📣 Hey @ArmaanMcleod, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
PR Summary
Add
QuoteCompletionText
method to CompletionHelpers class.This is to ensure quoted completions also get escaping done before surrounding quotes are added. Current code in
GetMatchingResults
just 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
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).