Skip to content

Commit

Permalink
Merge pull request #4871 from FabienTschanz/fix/array-comparison-in-r…
Browse files Browse the repository at this point in the history
…eport

Fix array comparison in report
  • Loading branch information
NikCharlebois committed Jul 16, 2024
2 parents 07c11a8 + fa8c008 commit 25e625a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Changes behaviour to not throw on empty configuration during report generation.
FIXES [#4559](https://github.com/microsoft/Microsoft365DSC/issues/4559)
FIXES [#4505](https://github.com/microsoft/Microsoft365DSC/issues/4505)
* Fixes an issue where the comparison treats empty arrays as an empty string.
FIXES [#4796](https://github.com/microsoft/Microsoft365DSC/issues/4796)

# 1.24.710.3

Expand Down
23 changes: 9 additions & 14 deletions Modules/Microsoft365DSC/Modules/M365DSCReport.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,7 @@ function Compare-M365DSCConfigurations
{
if ($propertyName -notin $filteredProperties)
{
$destinationPropertyName = $destinationResource.Keys | Where-Object -FilterScript { $_ -eq $propertyName }
if ([System.String]::IsNullOrEmpty($destinationPropertyName))
{
$destinationPropertyName = $propertyName
}
$destinationPropertyName = $propertyName

# Case where the property contains CIMInstances
if ($null -ne $sourceResource.$propertyName.Keys -and $sourceResource.$propertyName.Keys.Contains('CIMInstance'))
Expand Down Expand Up @@ -892,7 +888,7 @@ function Compare-M365DSCConfigurations
}
# Needs to be a separate nested if statement otherwise the ReferenceObject can be null and it will error out;
elseif ($destinationResource.ContainsKey($destinationPropertyName) -eq $false -or (-not [System.String]::IsNullOrEmpty($propertyName) -and
(-not [System.String]::IsNullOrEmpty($sourceResource.$propertyName) -and
($null -ne $sourceResource.$propertyName -and
$null -ne (Compare-Object -ReferenceObject ($sourceResource.$propertyName)`
-DifferenceObject ($destinationResource.$destinationPropertyName)))) -and
-not ([System.String]::IsNullOrEmpty($destinationResource.$destinationPropertyName) -and [System.String]::IsNullOrEmpty($sourceResource.$propertyName)))
Expand Down Expand Up @@ -952,11 +948,8 @@ function Compare-M365DSCConfigurations
{
if ($propertyName -notin $filteredProperties)
{
$sourcePropertyName = $destinationResource.Keys | Where-Object -FilterScript { $_ -eq $propertyName }
if ([System.String]::IsNullOrEmpty($sourcePropertyName))
{
$sourcePropertyName = $propertyName
}
$sourcePropertyName = $propertyName

# Case where the property contains CIMInstances
if ($null -ne $destinationResource.$propertyName.Keys -and $destinationResource.$propertyName.Keys.Contains('CIMInstance'))
{
Expand All @@ -979,13 +972,15 @@ function Compare-M365DSCConfigurations
foreach ($property in $instance.Keys)
{
if ($null -eq $sourceResourceInstance."$property" -or `
(-not [System.String]::IsNullOrEmpty($instance."$property") -and `
($null -ne $instance."$property" -and `
$null -ne (Compare-Object -ReferenceObject ($instance."$property")`
-DifferenceObject ($sourceResourceInstance."$property"))))
{
# Make sure we haven't already added this drift in the delta return object to prevent duplicates.
$existing = $delta | Where-Object -FilterScript {$_.ResourceName -eq $destinationResource.ResourceName -and `
$_.ResourceInstanceName -eq $destinationResource.ResourceInstanceName}
$existing = $delta | Where-Object -FilterScript {
$_.ResourceName -eq $destinationResource.ResourceName -and
$_.ResourceInstanceName -eq $destinationResource.ResourceInstanceName
}

$sameEntry = $null
if ($null -ne $existing)
Expand Down

0 comments on commit 25e625a

Please sign in to comment.