Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed ConvertTo-DWord to use UInt32 - Resolves #748 #761

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -1128,7 +1128,7 @@ function ConvertTo-Binary

<#
.SYNOPSIS
Converts the specified registry key value to an Int32 for the DWord registry type.
Converts the specified registry key value to an UInt32 for the DWord registry type.

.PARAMETER RegistryKeyValue
The registry key value to convert.
Expand All @@ -1155,7 +1155,7 @@ function ConvertTo-DWord
New-InvalidArgumentException -ArgumentName 'ValueData' -Message ($script:localizedData.ArrayNotAllowedForExpectedType -f 'Dword')
}

$dwordRegistryKeyValue = [System.Int32] 0
$dwordRegistryKeyValue = [System.UInt32] 0

if (($null -ne $RegistryKeyValue) -and ($RegistryKeyValue.Count -eq 1) -and (-not [System.String]::IsNullOrEmpty($RegistryKeyValue[0])))
{
Expand All @@ -1171,7 +1171,7 @@ function ConvertTo-DWord
$currentCultureInfo = [System.Globalization.CultureInfo]::CurrentCulture
$referenceValue = $null

if ([System.Int32]::TryParse($singleRegistryKeyValue, 'HexNumber', $currentCultureInfo, [ref] $referenceValue))
if ([System.UInt32]::TryParse($singleRegistryKeyValue, 'HexNumber', $currentCultureInfo, [ref] $referenceValue))
{
$dwordRegistryKeyValue = $referenceValue
}
Expand All @@ -1182,7 +1182,7 @@ function ConvertTo-DWord
}
else
{
$dwordRegistryKeyValue = [System.Int32]::Parse($singleRegistryKeyValue)
$dwordRegistryKeyValue = [System.UInt32]::Parse($singleRegistryKeyValue)
}
}

Expand Down
20 changes: 10 additions & 10 deletions tests/Unit/DSC_xRegistryResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3958,7 +3958,7 @@ try
$convertToDWordResult = ConvertTo-DWord @convertToDWordParameters

It 'Should return 0 as an Int32' {
$convertToDWordResult | Should -Be ([System.Int32] 0)
$convertToDWordResult | Should -Be ([System.UInt32] 0)
}
}

Expand All @@ -3974,7 +3974,7 @@ try
$convertToDWordResult = ConvertTo-DWord @convertToDWordParameters

It 'Should return 0 as an Int32' {
$convertToDWordResult | Should -Be ([System.Int32] 0)
$convertToDWordResult | Should -Be ([System.UInt32] 0)
}
}

Expand All @@ -3990,11 +3990,11 @@ try
$convertToDWordResult = ConvertTo-DWord @convertToDWordParameters

It 'Should return 0 as an Int32' {
$convertToDWordResult | Should -Be ([System.Int32] 0)
$convertToDWordResult | Should -Be ([System.UInt32] 0)
}
}

$testDWord1 = [System.Int32]::MaxValue
$testDWord1 = [System.UInt32]::MaxValue

Context 'Specified registry key value is an array containing a valid single string and Hex not specified' {
$convertToDWordParameters = @{
Expand All @@ -4013,7 +4013,7 @@ try
}

Context 'Specified registry key value is an array containing an invalid single string and Hex specified as True' {
$invalidHexDWord = 'InvalidInt32'
$invalidHexDWord = 'InvalidUInt32'
$convertToDWordParameters = @{
RegistryKeyValue = @( $invalidHexDWord )
Hex = $true
Expand All @@ -4028,7 +4028,7 @@ try

Context 'Specified registry key value is an array containing a valid single string and Hex specified as True' {
$validHexDWord = '0xA9'
$expectedInt32Value = 169
$expectedUInt32Value = 169

$convertToDWordParameters = @{
RegistryKeyValue = @( $validHexDWord.ToString() )
Expand All @@ -4042,13 +4042,13 @@ try
$convertToDWordResult = ConvertTo-DWord @convertToDWordParameters

It 'Should return the specified double word converted from a Hex value' {
$convertToDWordResult | Should -Be $expectedInt32Value
$convertToDWordResult | Should -Be $expectedUInt32Value
}
}

Context 'Specified registry key value is an array containing a valid single string of 0x00 and Hex specified as True' {
$validHexDWord = '0x00'
$expectedInt32Value = 0
$expectedUInt32Value = 0

$convertToDWordParameters = @{
RegistryKeyValue = @( $validHexDWord.ToString() )
Expand All @@ -4062,12 +4062,12 @@ try
$convertToDWordResult = ConvertTo-DWord @convertToDWordParameters

It 'Should return the specified double word converted from a Hex value' {
$convertToDWordResult | Should -Be $expectedInt32Value
$convertToDWordResult | Should -Be $expectedUInt32Value
}
}

Context 'Specified registry key value is an array with more than one string' {
$testDWord2 = [System.Int32]::MinValue
$testDWord2 = [System.UInt32]::MinValue

$convertToDWordParameters = @{
RegistryKeyValue = @( $testDWord1.ToString(), $testDWord2.ToString() )
Expand Down