Quote bare quote file paths if the path includes a double quote character by MartinGC94 · Pull Request #25631 · PowerShell/PowerShell
PR Summary
Fixes the logic for the file path completion so paths with double quote characters get single quotes added just like we do for other problematic characters in bare quote strings.
PR Context
Fixes #25629
PR Checklist
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Make sure all
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header - This PR is ready to merge. If this PR is a work in progress, please open this as a Draft Pull Request and mark it as Ready to Review when it is ready to merge.
- Breaking changes
- None
- OR
- Experimental feature(s) needed
- Experimental feature name(s):
- User-facing changes
- Not Applicable
- OR
- Documentation needed
- Issue filed:
- Testing - New and feature
- N/A or can only be tested interactively
- OR
- Make sure you've added a new test if existing tests do not effectively test the code changed
iSazonov
added
the
CL-General
label
Jun 4, 2025| _ = sb.Append('\''); | ||
| quotesAreNeeded = true; | ||
| // Bareword or singlequoted input string. | ||
| if (path[index].IsSingleQuote()) |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the method would be more readable if we ridded of useSingleQuoteEscapeRules and replace it with stringType is StringConstantType.SingleQuoted or StringConstantType.BareWord.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That check will change when my PR to keep variables when tab completing paths is merged. If someone is tab completing a bareword string with a variable it needs to use double quote rules.
| $null = New-Item -Path $TestFile1 -Force | ||
| $Expected = "'$($TestFile1.Insert($TestFile1.LastIndexOf($BadQuote), "'"))'" | ||
|
|
||
| $res = TabExpansion2 -inputScript "Get-ChildItem -Path '$TestDrive\" |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is intentional to have single quote it is not obvious so please add a comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters