diff --git a/src/System.Management.Automation/engine/Credential.cs b/src/System.Management.Automation/engine/Credential.cs index 26a1d0ac0c2..6056173d396 100644 --- a/src/System.Management.Automation/engine/Credential.cs +++ b/src/System.Management.Automation/engine/Credential.cs @@ -330,6 +330,12 @@ private static bool IsValidUserName(string input, out string user, out string domain) { + if (String.IsNullOrEmpty(input)) + { + user = domain = null; + return false; + } + SplitUserDomain(input, out user, out domain); if ((user == null) || diff --git a/test/powershell/engine/Basic/Credential.Tests.ps1 b/test/powershell/engine/Basic/Credential.Tests.ps1 new file mode 100644 index 00000000000..3612efb4c6a --- /dev/null +++ b/test/powershell/engine/Basic/Credential.Tests.ps1 @@ -0,0 +1,6 @@ +Describe "Credential tests" -Tags "CI" { + It "Explicit cast for an empty credential returns null" { + # We should explicitly check that the expression returns $null + [PSCredential]::Empty.GetNetworkCredential() | Should Be $null + } +}