Add support empty NoteProperty in Group-Object (#9109)

This commit is contained in:
Ilya
2019-03-13 11:22:05 +05:00
committed by GitHub
parent 9983297254
commit e75bd1482f
2 changed files with 14 additions and 2 deletions
@@ -113,12 +113,17 @@ namespace Microsoft.PowerShell.Commands
public override int GetHashCode()
{
if (PropertyValue == null)
{
return 0;
}
object baseObject = PSObject.Base(PropertyValue);
IComparable baseObjectComparable = baseObject as IComparable;
if (baseObject == null)
{
return 0;
}
if (baseObjectComparable != null)
if (baseObject is IComparable)
{
return baseObject.GetHashCode();
}
@@ -123,6 +123,13 @@ Describe "Group-Object" -Tags "CI" {
$result['Successful'].ErrorMessage.Count | Should -Be 4
$result['Successful'].ErrorMessage[0] | Should -Be ''
}
It "Should understand empty NoteProperty" {
$result = "dummy" | Select-Object -Property @{Name = 'X'; Expression = {}} | Group-Object X
$result.Count | Should -Be 1
$result[0].Name | Should -Be ""
$result[0].Group | Should -Be '@{X=}'
}
}
Describe "Check 'Culture' parameter in order object cmdlets (Group-Object, Sort-Object, Compare-Object)" -Tags "CI" {