From f039793b7bfccb585438db0eb3f3caf35686f3e7 Mon Sep 17 00:00:00 2001 From: Orion Date: Fri, 20 Sep 2024 21:52:48 +0800 Subject: [PATCH 1/2] fix(bin_match_json): check type before get attribute --- libexec/scoop-search.ps1 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index d94b18660d..847e33a193 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -30,7 +30,23 @@ function bin_match($manifest, $query) { function bin_match_json($json, $query) { [System.Text.Json.JsonElement]$bin = [System.Text.Json.JsonElement]::new() - if (!$json.RootElement.TryGetProperty('bin', [ref] $bin)) { return $false } + + # check if RootElement is object type + if ($json.RootElement.ValueKind -eq [System.Text.Json.JsonValueKind]::Object) { + # try to get 'bin' attribute + if (!$json.RootElement.TryGetProperty('bin', [ref] $bin)) { return $false } + } elseif ($json.RootElement.ValueKind -eq [System.Text.Json.JsonValueKind]::Array) { + # or if RootElement is an array, then do not use TryGetProperty + foreach ($item in $json.RootElement.EnumerateArray()) { + if ($item.ValueKind -eq [System.Text.Json.JsonValueKind]::Object -and $item.TryGetProperty('bin', [ref] $bin)) { + break + } + } + if ($bin.ValueKind -eq [System.Text.Json.JsonValueKind]::Undefined) { return $false } + } else { + return $false + } + $bins = @() if ($bin.ValueKind -eq [System.Text.Json.JsonValueKind]::String -and [System.IO.Path]::GetFileNameWithoutExtension($bin) -match $query) { $bins += [System.IO.Path]::GetFileName($bin) From 7531a597c783366b28e73c4bab381762fd00e0b6 Mon Sep 17 00:00:00 2001 From: Orion Date: Fri, 20 Sep 2024 22:41:07 +0800 Subject: [PATCH 2/2] making my commits verified ;-) --- libexec/scoop-search.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index 847e33a193..2ad75ad273 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -30,7 +30,6 @@ function bin_match($manifest, $query) { function bin_match_json($json, $query) { [System.Text.Json.JsonElement]$bin = [System.Text.Json.JsonElement]::new() - # check if RootElement is object type if ($json.RootElement.ValueKind -eq [System.Text.Json.JsonValueKind]::Object) { # try to get 'bin' attribute