Make Native globbing on UNIX return an absolute path when it is given an absolute path (#7106)

Fix #7089. Native globbing on UNIX was turning absolute paths into relative paths when it shouldn't. The code suppresses generating a relative path for paths starting with '~'. It also need to do the same for paths starting with '/'.
This commit is contained in:
Bruce Payette
2018-08-07 14:38:22 -07:00
committed by Travis Plunk
parent f858e6d207
commit 0c11582e6c
2 changed files with 9 additions and 3 deletions
@@ -254,8 +254,8 @@ namespace System.Management.Automation
// If it's a filesystem location then expand the wildcards
if (cwdinfo.Provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
{
// On UNIX, paths starting with ~ are not normalized
bool normalizePath = arg.Length == 0 || arg[0] != '~';
// On UNIX, paths starting with ~ or absolute paths are not normalized
bool normalizePath = arg.Length == 0 || ! (arg[0] == '~' || arg[0] == '/');
// See if there are any matching paths otherwise just add the pattern as the argument
Collection<PSObject> paths = null;
@@ -47,7 +47,13 @@ Describe 'Native UNIX globbing tests' -tags "CI" {
$a = $v,$v
/bin/ls $a[1] | Should -Match "abc.txt"
}
}
# Test globbing with absolute paths - it shouldn't turn absolute paths into relative paths (#7089)
It 'Should not normalize absolute paths' {
$matches = /bin/echo /etc/*
# Matched path should start with '/etc/' not '../..'
$matches.substring(0,5) | Should Be '/etc/'
}
It 'Globbing should not happen with quoted expressions' {
$v = "$TESTDRIVE/abc*"
/bin/echo "$v" | Should -BeExactly $v