diff --git a/src/System.Management.Automation/engine/parser/SymbolResolver.cs b/src/System.Management.Automation/engine/parser/SymbolResolver.cs index a453f0095ac..42091ba2e7b 100644 --- a/src/System.Management.Automation/engine/parser/SymbolResolver.cs +++ b/src/System.Management.Automation/engine/parser/SymbolResolver.cs @@ -498,8 +498,8 @@ private Collection GetModulesFromUsingModule(UsingStatementAst usi 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 18c3661d5af..8ea691888a5 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 } } } -