Skip to content

Commit

Permalink
check for existing relative path notation before adding current path …
Browse files Browse the repository at this point in the history
…period
  • Loading branch information
SteveL-MSFT committed Mar 11, 2024
1 parent 5333f3f commit 542b76c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Expand Up @@ -223,7 +223,8 @@ protected override void ProcessRecord()
// Do not insert './' if result path is not relative
if (!adjustedPath.StartsWith(
currentPath.Drive?.Root ?? currentPath.Path, StringComparison.OrdinalIgnoreCase) &&
!adjustedPath.StartsWith("." + currentPath.Provider.ItemSeparator, StringComparison.OrdinalIgnoreCase))
!adjustedPath.StartsWith("." + currentPath.Provider.ItemSeparator, StringComparison.OrdinalIgnoreCase) &&
!adjustedPath.StartsWith(".." + currentPath.Provider.ItemSeparator, StringComparison.OrdinalIgnoreCase))
{
adjustedPath = SessionState.Path.Combine(".", adjustedPath);
}
Expand Down
Expand Up @@ -127,4 +127,19 @@ Describe "Resolve-Path returns proper path" -Tag "CI" {
Pop-Location
}
}

It 'does not return path containing both current and parent directory' {
$testDir = Join-Path $TestDrive "testDir"
$null = New-Item -Path $testDir -ItemType Directory -Force
$testFile = Join-Path $testDrive "testfile"
$null = New-Item -Path $testFile -ItemType File -Force
try {
Push-Location $testDir
$result = Resolve-Path -Path "..\testfile" -Relative
$result | Should -BeExactly (Join-Path '..' 'testfile')
}
finally {
Pop-Location
}
}
}

0 comments on commit 542b76c

Please sign in to comment.