Skip to content

Commit

Permalink
GetRelativePath should check if path is already relative before calli…
Browse files Browse the repository at this point in the history
…ng [IO.Path]::GetRelativePath
  • Loading branch information
danieljurek authored and azure-sdk committed Oct 13, 2021
1 parent 0e1391a commit 276bf07
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions eng/common/scripts/Save-Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ function GetRelativePath($path) {
if (!$path) {
return ''
}

# If the path is already relative return the path. Calling `GetRelativePath`
# on a relative path converts the relative path to an absolute path based on
# the current working directory which can result in unexpected outputs.
if (![IO.Path]::IsPathRooted($path)) {
return $path
}

$relativeTo = Resolve-Path $PSScriptRoot/../../../
# Replace "\" with "/" so the path is valid across other platforms and tools
$relativePath = [IO.Path]::GetRelativePath($relativeTo, $path) -replace "\\", '/'
Expand Down

0 comments on commit 276bf07

Please sign in to comment.