mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Format-Hex - Fix Grouping Behaviour with Boolean values (#11587)
* Resolve issue with grouping bools & ints We were not flushing the input buffer immediately when a different type is encountered. This caused some odd behaviour when piping in a mix of bools and ints. Fix is to immediately flush the input buffer when the incoming object is a different type than anything we have buffered.
This commit is contained in:
committed by
Ilya
parent
caa50510c2
commit
b71d983306
+1
@@ -403,6 +403,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (_lastInputType != null && baseType != _lastInputType)
|
||||
{
|
||||
_groupInput = false;
|
||||
FlushInputBuffer();
|
||||
}
|
||||
|
||||
_lastInputType = baseType;
|
||||
|
||||
@@ -63,6 +63,12 @@ public enum TestSByteEnum : sbyte {
|
||||
}
|
||||
|
||||
$testCases = @(
|
||||
@{
|
||||
Name = "Can process bool type 'fhx -InputObject `$true'"
|
||||
InputObject = $true
|
||||
Count = 1
|
||||
ExpectedResult = "00000000 01 00 00 00"
|
||||
}
|
||||
@{
|
||||
Name = "Can process byte type 'fhx -InputObject [byte]5'"
|
||||
InputObject = [byte]5
|
||||
@@ -159,6 +165,12 @@ public enum TestSByteEnum : sbyte {
|
||||
}
|
||||
|
||||
$testCases = @(
|
||||
@{
|
||||
Name = "Can process bool type '`$true | fhx'"
|
||||
InputObject = $true
|
||||
Count = 1
|
||||
ExpectedResult = "0000000000000000 01"
|
||||
}
|
||||
@{
|
||||
Name = "Can process byte type '[byte]5 | fhx'"
|
||||
InputObject = [byte]5
|
||||
@@ -227,6 +239,13 @@ public enum TestSByteEnum : sbyte {
|
||||
ExpectedResult = "0000000000000000 F1 12 15 FB ñ��û"
|
||||
ExpectedSecondResult = "0000000000000000 01 02 03 04 05 06 ������"
|
||||
}
|
||||
@{
|
||||
Name = "Can process jagged array type '[bool[]](`$true, `$false), [int[]](1, 2, 3, 4) | fhx'"
|
||||
InputObject = [bool[]]($true, $false), [int[]](1, 2, 3, 4)
|
||||
Count = 2
|
||||
ExpectedResult = "0000000000000000 01 00 00 00 00 00 00 00 �"
|
||||
ExpectedSecondResult = "0000000000000000 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 � � � �"
|
||||
}
|
||||
@{
|
||||
Name = "Can process PS-native enum array '[TestEnum[]]('TestOne', 'TestTwo', 'TestThree', 'TestFour') | fhx'"
|
||||
InputObject = [TestEnum[]]('TestOne', 'TestTwo', 'TestThree', 'TestFour')
|
||||
@@ -291,6 +310,19 @@ public enum TestSByteEnum : sbyte {
|
||||
"System.UInt16[]"
|
||||
).ForEach{ [regex]::Escape($_) } -join '|'
|
||||
}
|
||||
@{
|
||||
InputScript = { $true, $false, $true, 123, 100, 76, $true, $false }
|
||||
Count = 3
|
||||
ExpectedResults = @(
|
||||
"0000000000000000 01 00 00 00 00 00 00 00 01 00 00 00 � �"
|
||||
"0000000000000000 7B 00 00 00 64 00 00 00 4C 00 00 00 { d L"
|
||||
"0000000000000000 01 00 00 00 00 00 00 00 �"
|
||||
)
|
||||
ExpectedLabels = @(
|
||||
"System.Boolean"
|
||||
"System.Int32"
|
||||
).ForEach{ [regex]::Escape($_) } -join '|'
|
||||
}
|
||||
)
|
||||
|
||||
It 'can process jagged input: <InputScript>' -TestCases $heterogenousInputCases {
|
||||
@@ -356,8 +388,7 @@ public enum TestSByteEnum : sbyte {
|
||||
|
||||
if ($PathCase) {
|
||||
$result = Format-Hex -Path $Path
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
# LiteralPath
|
||||
$result = Format-Hex -LiteralPath $Path
|
||||
}
|
||||
@@ -380,8 +411,7 @@ public enum TestSByteEnum : sbyte {
|
||||
$Result.Bytes[-1] | Should -Be 0x0A
|
||||
$Result.Bytes[-2] | Should -Be 0x0D
|
||||
$Result.Bytes.Length | Should -Be 14
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$Result.Bytes[-1] | Should -Be 0x0A
|
||||
$Result.Bytes.Length | Should -Be 13
|
||||
}
|
||||
@@ -507,8 +537,7 @@ public enum TestSByteEnum : sbyte {
|
||||
|
||||
if ($PathCase) {
|
||||
$output = Format-Hex -Path $InvalidPath, $inputFile1 -ErrorVariable errorThrown -ErrorAction SilentlyContinue
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
# LiteralPath
|
||||
$output = Format-Hex -LiteralPath $InvalidPath, $inputFile1 -ErrorVariable errorThrown -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user