From c4108c880bfd1148d3724551428656f3163bcbc7 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Fri, 5 Dec 2025 14:48:09 -0500 Subject: [PATCH] Update samy.ps1 --- samy.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/samy.ps1 b/samy.ps1 index 2cd08bd..720253d 100644 --- a/samy.ps1 +++ b/samy.ps1 @@ -1328,6 +1328,12 @@ function Send-JSON { if (-not $Context -or -not $Context.Response) { return } + + # If caller gave us $null, reply with an empty array instead of blowing up + if ($null -eq $Object) { + $Object = @() + } + $json = $Object | ConvertTo-Json -Depth 5 $bytes = [Text.Encoding]::UTF8.GetBytes($json) $Context.Response.ContentType = 'application/json' @@ -1794,6 +1800,12 @@ function Invoke-GetPrinters { # NOTE: We never log the actual password $printers = Get-SamyClientListFromServer -Uri $uri -Password $password + # 🔹 EXTRA SAFETY: never pass $null to Send-JSON + if ($null -eq $printers) { + Write-LogHybrid "Get-SamyClientListFromServer returned `$null; sending empty JSON array." Warning Printers -LogToEvent + $printers = @() + } + # Return raw objects as JSON; JS will filter/group Send-JSON $Context $printers }