diff --git a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs index 4b0b2d9afa7..7975c1e5bbf 100644 --- a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs +++ b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs @@ -258,8 +258,8 @@ private void PossiblyGlobArg(string arg, bool usedQuotes) // 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 paths = null; diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeUnixGlobbing.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeUnixGlobbing.Tests.ps1 index b0593989743..7e65b41ba9c 100644 --- a/test/powershell/Language/Scripting/NativeExecution/NativeUnixGlobbing.Tests.ps1 +++ b/test/powershell/Language/Scripting/NativeExecution/NativeUnixGlobbing.Tests.ps1 @@ -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