Allow / in relative paths for using module (#7424) (#12492)

This commit is contained in:
Joshua Cotton
2020-04-30 11:20:53 -07:00
committed by GitHub
parent 8128a036f7
commit c19a417321
2 changed files with 16 additions and 4 deletions
@@ -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);
@@ -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 .<Separator>' -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
}
}
}