Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ bool TryGetBoolValue(string arg, out bool boolValue)
_collectedArgs.Add(new CommandParameter(pendingParameter, arg));
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(':');
if (offset >= 0)
Expand Down
19 changes: 18 additions & 1 deletion test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
$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"}
) {
Expand All @@ -226,6 +226,23 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
& $powershell $testdrive/$Filename
$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" {
Expand Down