Skip to content

Commit

Permalink
(MODULES-7661) Fix JSON encoding for single object arrays
Browse files Browse the repository at this point in the history
Previously the powershell tests were failing on tests where they returned a
single JSON object.  This is due to percularity in PowerShell where single
element arrays get reduced to just the item.  This commit changes the JSON
encoding to insert a begin and end bracket into the JSON string which forces the
output to be an array again.  This only applies for single elements not for
empty or multi element arrays.
  • Loading branch information
glennsarti committed Sep 10, 2018
1 parent 354c34e commit 786717c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tasks/update_history.ps1
Expand Up @@ -76,7 +76,7 @@ Function Invoke-ExecuteTask($Detailed, $Title, $UpdateID, $MaximumUpdates) {

$historyCount = $Searcher.GetTotalHistoryCount()
if ($historyCount -gt $MaximumUpdates) { $historyCount = $MaximumUpdates }
$Searcher.QueryHistory(0, $historyCount) |
$Result = $Searcher.QueryHistory(0, $historyCount) |
Where-Object { [String]::IsNullOrEmpty($Title) -or ($_.Title -match $Title) } |
Where-Object { [String]::IsNullOrEmpty($UpdateID) -or ($_.UpdateIdentity.UpdateID -eq $UpdateID) } |
ForEach-Object -Process {
Expand Down Expand Up @@ -110,7 +110,17 @@ Function Invoke-ExecuteTask($Detailed, $Title, $UpdateID, $MaximumUpdates) {
}

New-Object -TypeName PSObject -Property $props
} | ConvertTo-JSON
}

if ($Result -ne $null) {
if ($Result.GetType().ToString() -ne 'System.Object[]') {
'[ ' + ($Result | ConvertTo-JSON) + ' ]'
} else {
$Result | ConvertTo-JSON
}
} else {
'[ ]'
}
}

if (-Not $NoOperation) { Invoke-ExecuteTask -Detailed $Detailed -Title $Title -UpdateID $UpdateID -MaximumUpdates $MaximumUpdates }

0 comments on commit 786717c

Please sign in to comment.