From fac4267d784dee11d75c7ad7dfa5d554cc6d5c6b Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Thu, 9 Jul 2020 15:29:18 -0700 Subject: [PATCH] Fix handling of numerical configuration properties across PS5 and PS7 ConvertFrom-Json defaults numbers to different types depending on the PowerShell version. PS5 defaults numbers to [Int32] while PS7 defaults numbers to [int64], but both versions default to [Int32] in [PSCustomObjects]. Due to this, if you had a number config value saved, on PS7 it would be ignored and the default value would be used because the expected and actual types wouldn't match. I've updated `Resolve-PropertyValue` to have equivalence logic for number types to avoid this issue. --- GitHubConfiguration.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index 7c50f858..944b2621 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -466,16 +466,18 @@ function Resolve-PropertyValue if ($Type -eq 'Boolean') { $typeType = [Boolean] } if ($Type -eq 'Int32') { $typeType = [Int32] } if ($Type -eq 'Int64') { $typeType = [Int64] } + $numberEquivalents = @('Int32', 'Int64', 'long', 'int') if (Test-PropertyExists -InputObject $InputObject -Name $Name) { - if ($InputObject.$Name -is $typeType) + if (($InputObject.$Name -is $typeType) -or + (($Type -in $numberEquivalents) -and ($InputObject.$Name.GetType().Name -in $numberEquivalents))) { return $InputObject.$Name } else { - $message = "The locally cached $Name configuration was not of type $Type. Reverting to default value." + $message = "The locally cached $Name configuration was not of type $Type (it was $($InputObject.$Name.GetType())). Reverting to default value." Write-Log -Message $message -Level Warning return $DefaultValue }