@@ -2257,6 +2257,42 @@ param ($Param1)
22572257
22582258 Remove-Item - LiteralPath $LiteralPath
22592259 }
2260+
2261+ It " Should add single quotes if there are double quotes in bare word file path" {
2262+ $BadQuote = [char ]8220
2263+ $TestFile1 = Join-Path - Path $TestDrive - ChildPath " Test1${BadQuote} File"
2264+ $null = New-Item - Path $TestFile1 - Force
2265+ $res = TabExpansion2 - inputScript " Get-ChildItem -Path $TestDrive \"
2266+ ($res.CompletionMatches | Where-Object ListItemText -Like " Test1?File" ).CompletionText | Should - Be " '$TestFile1 '"
2267+ Remove-Item - LiteralPath $TestFile1 - Force
2268+ }
2269+
2270+ It " Should escape double quote if the input string uses double quotes" {
2271+ $BadQuote = [char ]8220
2272+ $TestFile1 = Join-Path - Path $TestDrive - ChildPath " Test1${BadQuote} File"
2273+ $null = New-Item - Path $TestFile1 - Force
2274+ $res = TabExpansion2 - inputScript " Get-ChildItem -Path `" $TestDrive \"
2275+ $Expected = " `" $ ( $TestFile1.Insert ($TestFile1.LastIndexOf ($BadQuote ), ' `' )) `" "
2276+ ($res.CompletionMatches | Where-Object ListItemText -Like " Test1?File" ).CompletionText | Should - Be $Expected
2277+ Remove-Item - LiteralPath $TestFile1 - Force
2278+ }
2279+
2280+ It " Should escape single quotes in file paths" {
2281+ $SingleQuote = " '"
2282+ $TestFile1 = Join-Path - Path $TestDrive - ChildPath " Test1${SingleQuote} File"
2283+ $null = New-Item - Path $TestFile1 - Force
2284+ # Regardless if the input string was singlequoted or not, we expect to add surrounding single quotes and
2285+ # escape the single quote in the file path with another singlequote.
2286+ $Expected = " '$ ( $TestFile1.Insert ($TestFile1.LastIndexOf ($SingleQuote ), " '" )) '"
2287+
2288+ $res = TabExpansion2 - inputScript " Get-ChildItem -Path '$TestDrive \"
2289+ ($res.CompletionMatches | Where-Object ListItemText -Like " Test1?File" ).CompletionText | Should - Be $Expected
2290+
2291+ $res = TabExpansion2 - inputScript " Get-ChildItem -Path $TestDrive \"
2292+ ($res.CompletionMatches | Where-Object ListItemText -Like " Test1?File" ).CompletionText | Should - Be $Expected
2293+
2294+ Remove-Item - LiteralPath $TestFile1 - Force
2295+ }
22602296 }
22612297
22622298 It ' Should correct slashes in UNC path completion' - Skip:(! $IsWindows ) {
0 commit comments