Skip to content
Merged
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
10 changes: 1 addition & 9 deletions ReverseDSC.Core.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -616,15 +616,7 @@ function Get-DSCBlock
}
'^(Object\[\]|Microsoft\.Management\.Infrastructure\.CimInstance\[\])$'
{
if ($paramType -ne "Microsoft.Management.Infrastructure.CimInstance[]" -and
$paramValue.Length -gt 0 -and $null -ne $paramValue[0] -and $paramValue[0].GetType().Name -eq "String")
{
$value = ConvertTo-DSCStringArrayValue -Value $paramValue -NoEscape $isNoEscape -AllowVariables $AllowVariablesInStrings
}
else
{
$value = ConvertTo-DSCObjectArrayValue -Value $paramValue -NoEscape $isNoEscape -AllowVariables $AllowVariablesInStrings
}
$value = ConvertTo-DSCObjectArrayValue -Value $paramValue -NoEscape $isNoEscape -AllowVariables $AllowVariablesInStrings
}
'^CimInstance$'
{
Expand Down
2 changes: 1 addition & 1 deletion ReverseDSC.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Generated on: 2026/04/04
#
@{
ModuleVersion = '2.0.0.33'
ModuleVersion = '2.0.0.34'
GUID = '6c1176a0-4fac-4134-8ca2-3fa8a21a7b90'
Author = 'Microsoft Corporation'
CompanyName = 'Microsoft Corporation'
Expand Down
29 changes: 22 additions & 7 deletions Tests/ReverseDSC.Core.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ Describe 'ConvertTo-DSCStringArrayValue' {
$result = ConvertTo-DSCStringArrayValue -Value @('Item1')
$result | Should -Be '@("Item1")'
}

It 'Should return @() for array with null element' {
$result = ConvertTo-DSCStringArrayValue -Value @( $null )
$result | Should -Be '@()'
}
}

Context 'When the value is a multi-element array' {
Expand Down Expand Up @@ -250,6 +255,11 @@ Describe 'ConvertTo-DSCIntegerArrayValue' {
$result = ConvertTo-DSCIntegerArrayValue -Value @(42)
$result | Should -Be '@(42)'
}

It 'Should return @() for array with null element' {
$result = ConvertTo-DSCStringArrayValue -Value @( $null )
$result | Should -Be '@()'
}
}
}

Expand All @@ -271,6 +281,11 @@ Describe 'ConvertTo-DSCObjectArrayValue' {
$result = ConvertTo-DSCObjectArrayValue -Value @('A', 'B', 'C')
$result | Should -Be '@("A","B","C")'
}

It 'Should return @() for array with null element' {
$result = ConvertTo-DSCStringArrayValue -Value @( $null )
$result | Should -Be '@()'
}
}

Context 'When the value contains hashtables' {
Expand All @@ -295,7 +310,7 @@ Describe 'ConvertTo-DSCObjectArrayValue' {
@{ Items = @('A', 'B') }
)
$result = ConvertTo-DSCObjectArrayValue -Value $value
$result | Should -Match "@\("
$result | Should -Be "@(@{Items=@('A', 'B')})"
}
}

Expand Down Expand Up @@ -672,7 +687,8 @@ function Set-TargetResource
Enabled = $true
}
$result = Get-DSCBlock -ModulePath $testModulePath -Params $params
$result | Should -Match '\$True'
$result | Should -Match '= \$True;'
$result | Should -Match '= "Test";'
}
}

Expand All @@ -683,9 +699,8 @@ function Set-TargetResource
Items = @('Item1', 'Item2')
}
$result = Get-DSCBlock -ModulePath $testModulePath -Params $params
$result | Should -Match '@\('
$result | Should -Match 'Item1'
$result | Should -Match 'Item2'
$result | Should -Match '@\("Item1","Item2"\);'
$result | Should -Match '= "Test";'
}
}

Expand Down Expand Up @@ -744,8 +759,8 @@ function Set-TargetResource
Items = @{ SubKey = 'SubValue' }
}
$result = Get-DSCBlock -ModulePath $testModulePath -Params $params
$result | Should -Match '@\{'
$result | Should -Match 'SubKey'
$result | Should -Match '@\{SubKey = "SubValue"; \}'
$result | Should -Match '= "Test";'
}
}
}
Expand Down
Loading