Allow passing just a dash as an arg to a file via pwsh (#9479)
This commit is contained in:
parent
7de4210760
commit
d318e7727e
|
@ -1214,7 +1214,7 @@ namespace Microsoft.PowerShell
|
||||||
_collectedArgs.Add(new CommandParameter(pendingParameter, arg));
|
_collectedArgs.Add(new CommandParameter(pendingParameter, arg));
|
||||||
pendingParameter = null;
|
pendingParameter = null;
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(arg) && SpecialCharacters.IsDash(arg[0]))
|
else if (!string.IsNullOrEmpty(arg) && SpecialCharacters.IsDash(arg[0]) && arg.Length > 1)
|
||||||
{
|
{
|
||||||
int offset = arg.IndexOf(':');
|
int offset = arg.IndexOf(':');
|
||||||
if (offset >= 0)
|
if (offset >= 0)
|
||||||
|
|
|
@ -217,7 +217,7 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
|
||||||
$observed | Should -Be $BoolValue
|
$observed | Should -Be $BoolValue
|
||||||
}
|
}
|
||||||
|
|
||||||
It "-File '<filename>' should return exit code from script" -TestCases @(
|
It "-File '<filename>' should return exit code from script" -TestCases @(
|
||||||
@{Filename = "test.ps1"},
|
@{Filename = "test.ps1"},
|
||||||
@{Filename = "test"}
|
@{Filename = "test"}
|
||||||
) {
|
) {
|
||||||
|
@ -226,6 +226,23 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
|
||||||
& $powershell $testdrive/$Filename
|
& $powershell $testdrive/$Filename
|
||||||
$LASTEXITCODE | Should -Be 123
|
$LASTEXITCODE | Should -Be 123
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "A single dash should be passed as an arg" {
|
||||||
|
$testScript = @'
|
||||||
|
[CmdletBinding()]param(
|
||||||
|
[string]$p1,
|
||||||
|
[string]$p2,
|
||||||
|
[Parameter(ValueFromPipeline)][string]$InputObject
|
||||||
|
)
|
||||||
|
process{
|
||||||
|
$input.replace($p1, $p2)
|
||||||
|
}
|
||||||
|
'@
|
||||||
|
$testFilePath = Join-Path $TestDrive "test.ps1"
|
||||||
|
Set-Content -Path $testFilePath -Value $testScript
|
||||||
|
$observed = echo hello | pwsh $testFilePath e -
|
||||||
|
$observed | Should -BeExactly "h-llo"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "-SettingsFile Commandline switch" {
|
Context "-SettingsFile Commandline switch" {
|
||||||
|
|
Loading…
Reference in a new issue