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 @@ -534,7 +534,7 @@ internal static void EarlyParse(string[] args)

string switchKey = switchKeyResults.SwitchKey;

if (MatchSwitch(switchKey, match: "settingsfile", smallestUnambiguousMatch: "settings"))
if (!string.IsNullOrEmpty(switchKey) && MatchSwitch(switchKey, match: "settingsfile", smallestUnambiguousMatch: "settings"))
{
// parse setting file arg and don't write error as there is no host yet.
if (!TryParseSettingFileHelper(args, ++i, parser: null))
Expand Down
10 changes: 10 additions & 0 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
$observed = echo hello | pwsh -noprofile $testFilePath e -
$observed | Should -BeExactly "h-llo"
}

It "Empty command should fail" {
pwsh -noprofile -c ''
$LASTEXITCODE | Should -Be 64
}

It "Whitespace command should succeed" {
pwsh -noprofile -c ' ' | Should -BeNullOrEmpty
$LASTEXITCODE | Should -Be 0
}
}

Context "-Login pwsh switch" {
Expand Down