From 0c11582e6c4db023bf12dd05342430dfe3028e79 Mon Sep 17 00:00:00 2001 From: Bruce Payette Date: Tue, 7 Aug 2018 14:38:22 -0700 Subject: [PATCH] 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 '/'. --- .../engine/NativeCommandParameterBinder.cs | 4 ++-- .../NativeExecution/NativeUnixGlobbing.Tests.ps1 | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs index fb3031d3a8..875cf59cbb 100644 --- a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs +++ b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs @@ -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 paths = null; diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeUnixGlobbing.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeUnixGlobbing.Tests.ps1 index b059398974..7e65b41ba9 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