8000 Fix UNC path completion regression (#20419) (#20541) · PowerShell/PowerShell@bdf1cfd · GitHub
[go: up one dir, main page]

Skip to conten 8000 t

Commit bdf1cfd

Browse files
Fix UNC path completion regression (#20419) (#20541)
1 parent 58d1b6f commit bdf1cfd

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,22 +4629,19 @@ private static List<CompletionResult> GetFileSystemProviderResults(
46294629
string basePath;
46304630
if (!relativePaths)
46314631
{
4632-
string providerName = $"{provider.ModuleName}\\{provider.Name}::";
4633-
if (pathInfo.Path.StartsWith(providerName, StringComparison.OrdinalIgnoreCase))
4632+
if (pathInfo.Drive is null)
46344633
{
4635-
basePath = pathInfo.Path.Substring(providerName.Length);
4634+
basePath = dirInfo.FullName;
46364635
}
46374636
else
46384637
{
4639-
providerName = $"{provider.Name}::";
4640-
if (pathInfo.Path.StartsWith(providerName, StringComparison.OrdinalIgnoreCase))
4641-
{
4642-
basePath = pathInfo.Path.Substring(providerName.Length);
4643-
}
4644-
else
4645-
{
4646-
basePath = pathInfo.Path;
4647-
}
4638+
int stringStartIndex = pathInfo.Drive.Root.EndsWith(provider.ItemSeparator) && pathInfo.Drive.Root.Length > 1
4639+
? pathInfo.Drive.Root.Length - 1
4640+
: pathInfo.Drive.Root.Length;
4641+
4642+
basePath = pathInfo.Drive.VolumeSeparatedByColon
4643+
? string.Concat(pathInfo.Drive.Name, ":", dirInfo.FullName.AsSpan(stringStartIndex))
4644+
: string.Concat(pathInfo.Drive.Name, dirInfo.FullName.AsSpan(stringStartIndex));
46484645
}
46494646

46504647
basePath = basePath.EndsWith(provider.ItemSeparator)

test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,11 @@ class InheritedClassTest : System.Attribute
12761276
}
12771277
}
12781278

1279+
It 'Should correct slashes in UNC path completion' -Skip:(!$IsWindows) {
1280+
$Res = TabExpansion2 -inputScript 'Get-ChildItem //localhost/c$/Windows'
1281+
$Res.CompletionMatches[0].CompletionText | Should -Be "'\\localhost\c$\Windows'"
1282+
}
1283+
12791284
It 'Should keep custom drive names when completing file paths' {
12801285
$TempDriveName = "asdf"
12811286
$null = New-PSDrive -Name $TempDriveName -PSProvider FileSystem -Root $HOME

0 commit comments

Comments
 (0)
0