Skip to content

Commit

Permalink
🩹 [Patch]: Update JSON conversion logic in ConvertTo-GitHubOutput.ps1…
Browse files Browse the repository at this point in the history
… to handle string normalization and non-string values
  • Loading branch information
MariusStorhaug committed Feb 24, 2025
1 parent d9f3c4d commit df9161b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/functions/private/Commands/ConvertTo-GitHubOutput.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@
Write-Debug 'Property value:'
Write-Debug ($InputObject | Out-String)

# Convert hashtable or PSCustomObject to compressed JSON
if (-not ($value -is [string])) {
# This condition now catches objects, hashtables, and arrays.
# For each property value:
if ($value -is [string]) {
if (Test-Json $value -ErrorAction SilentlyContinue) {
# Normalize valid JSON strings to a consistent format.
$value = ($value | ConvertFrom-Json) | ConvertTo-Json -Compress -Depth 100
}
} else {
# For non-string values, convert to JSON.
$value = $value | ConvertTo-Json -Compress -Depth 100
}


$guid = [Guid]::NewGuid().ToString()
$EOFMarker = "EOF_$guid"
$outputLines += "$key<<$EOFMarker"
Expand Down

0 comments on commit df9161b

Please sign in to comment.