diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 830135f516c..84917e3b5c8 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -146,7 +146,12 @@ private static string GetCorrectCasedPath(string path) else if (string.IsNullOrEmpty(item)) { // This handles the trailing slash case - continue; + if (!exactPath.EndsWith(StringLiterals.DefaultPathSeparator)) + { + exactPath += StringLiterals.DefaultPathSeparator; + } + + break; } else if (item.Contains('~')) { @@ -159,11 +164,6 @@ private static string GetCorrectCasedPath(string path) } } - if (path.EndsWith(StringLiterals.DefaultPathSeparator)) - { - return exactPath + StringLiterals.DefaultPathSeparator; - } - return exactPath; } else diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 index c9be5e10f8f..3cc07f85f35 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Item.Tests.ps1 @@ -61,6 +61,11 @@ Describe "Get-Item" -Tags "CI" { $result.Exists | Should -BeTrue } + It "Should return correct result for ToString() on root of drive" { + $root = $IsWindows ? "${env:SystemDrive}\" : "/" + (Get-Item -Path $root).ToString() | Should -BeExactly $root + } + Context "Test for Include, Exclude, and Filter" { BeforeAll { ${testBaseDir} = "${TESTDRIVE}/IncludeExclude"