From c19a417321b17b1f52dc2ab1c8316aa4e2a08d12 Mon Sep 17 00:00:00 2001 From: Joshua Cotton Date: Thu, 30 Apr 2020 14:20:53 -0400 Subject: [PATCH] Allow `/` in relative paths for `using module` (#7424) (#12492) --- .../engine/parser/SymbolResolver.cs | 4 ++-- .../Classes/scripting.Classes.using.tests.ps1 | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/System.Management.Automation/engine/parser/SymbolResolver.cs b/src/System.Management.Automation/engine/parser/SymbolResolver.cs index a453f0095a..42091ba2e7 100644 --- a/src/System.Management.Automation/engine/parser/SymbolResolver.cs +++ b/src/System.Management.Automation/engine/parser/SymbolResolver.cs @@ -498,8 +498,8 @@ namespace System.Management.Automation.Language return null; } - // case 1: relative path. Relative for file in the same folder should include .\ - bool isPath = fullyQualifiedNameStr.Contains(@"\"); + // case 1: relative path. Relative for file in the same folder should include .\ or ./ + bool isPath = fullyQualifiedNameStr.Contains('\\') || fullyQualifiedNameStr.Contains('/'); if (isPath && !LocationGlobber.IsAbsolutePath(fullyQualifiedNameStr)) { string rootPath = Path.GetDirectoryName(_parser._fileName); diff --git a/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 b/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 index 18c3661d5a..8ea691888a 100644 --- a/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 +++ b/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 @@ -339,7 +339,7 @@ using module Foo } } - Context 'Side by side' { + Context 'Side by side' { BeforeAll { # Add side-by-side module $newVersion = '3.4.5' @@ -523,6 +523,19 @@ using module FooForPaths Pop-Location } } + + It 'can be accessed by relative path with .' -TestCases @( + @{ Separator = '\' }, + @{ Separator = '/' } + ) { + param([string]$Separator) + $name = 'relative-slash-paths' + 'function Get-TestString { "Worked" }' | Set-Content "TestDrive:\modules\$name.psm1" + + "using module .$Separator$name.psm1; Get-TestString" | Set-Content "TestDrive:\modules\$name.ps1" + + & "TestDrive:\modules\$name.ps1" | Should -BeExactly "Worked" + } } Context "module has non-terminating error handled with 'SilentlyContinue'" { @@ -547,4 +560,3 @@ using module $testFile } } } -