diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 9c9e1256ecd9..2694bb7e9502 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -4925,12 +4925,15 @@ private static string GetChildNameFromPsObject(dynamic psObject, char separator) for (int i = 0; i < path.Length; i++) { + // on Windows, we need to preserve the expanded home path as native commands don't understand it +#if UNIX if (i == homeIndex) { _ = sb.Append('~'); i += homePath.Length - 1; continue; } +#endif EscapeCharIfNeeded(sb, path, i, stringType, literalPath, useSingleQuoteEscapeRules, ref quotesAreNeeded); _ = sb.Append(path[i]); diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 8a4c838d2b3f..22ff201c45a1 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -1409,12 +1409,16 @@ class InheritedClassTest : System.Attribute $res.CompletionMatches[0].CompletionText | Should -Be "`"$expectedPath`"" } - It "Should keep '~' in completiontext when it's used to refer to home in input" { + It "Should handle '~' in completiontext when it's used to refer to home in input" { $res = TabExpansion2 -inputScript "~$separator" # select the first answer which does not have a space in the completion (those completions look like & '3D Objects') $observedResult = $res.CompletionMatches.Where({$_.CompletionText.IndexOf("&") -eq -1})[0].CompletionText $completedText = $res.CompletionMatches.CompletionText -join "," - $observedResult | Should -BeLike "~$separator*" -Because "$completedText" + if ($IsWindows) { + $observedResult | Should -BeLike "$home$separator*" -Because "$completedText" + } else { + $observedResult | Should -BeLike "~$separator*" -Because "$completedText" + } } It "Should use '~' as relative filter text when not followed by separator" {