Skip to content

Commit

Permalink
fix(json): Don't serialize jsonpath return if only one result (#6066)
Browse files Browse the repository at this point in the history
Co-authored-by: Hsiao-nan Cheung <[email protected]>
  • Loading branch information
ccyykkcyk and niheaven authored Jul 22, 2024
1 parent 429ba7a commit 0cb479a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug Fixes

- **scoop-alias:** Fix 'Option --verbose not recognized.' ([#6062](https://github.com/ScoopInstaller/Scoop/issues/6062))
- **json:** Don't serialize jsonpath return if only one result ([#6066](https://github.com/ScoopInstaller/Scoop/issues/6066))

## [v0.5.1](https://github.com/ScoopInstaller/Scoop/compare/v0.5.0...v0.5.1) - 2024-07-16

Expand Down
2 changes: 1 addition & 1 deletion lib/json.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function json_path([String] $json, [String] $jsonpath, [Hashtable] $substitution
# Return versions in reverse order
$result = [System.Linq.Enumerable]::Reverse($result)
}
if ($single) {
if ($result.Length -eq 1 -or $single) {
# Extract First value
$result = [System.Linq.Enumerable]::First($result)
# Convert first value to string
Expand Down
12 changes: 6 additions & 6 deletions libexec/scoop-virustotal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ Function Get-VirusTotalResultByHash ($hash, $url, $app) {
$response = Invoke-WebRequest -Uri $api_url -Method GET -Headers $headers -UseBasicParsing
$result = $response.Content
$stats = json_path $result '$.data.attributes.last_analysis_stats'
[int]$malicious = json_path $stats '$[0].malicious' $null $false $true
[int]$suspicious = json_path $stats '$[0].suspicious' $null $false $true
[int]$timeout = json_path $stats '$[0].timeout' $null $false $true
[int]$undetected = json_path $stats '$[0].undetected' $null $false $true
[int]$malicious = json_path $stats '$[0].malicious'
[int]$suspicious = json_path $stats '$[0].suspicious'
[int]$timeout = json_path $stats '$[0].timeout'
[int]$undetected = json_path $stats '$[0].undetected'
[int]$unsafe = $malicious + $suspicious
[int]$total = $unsafe + $undetected
[int]$fileSize = json_path $result '$.data.attributes.size' $null $false $true
$report_hash = json_path $result '$.data.attributes.sha256' $null $false $true
[int]$fileSize = json_path $result '$.data.attributes.size'
$report_hash = json_path $result '$.data.attributes.sha256'
$report_url = "https://www.virustotal.com/gui/file/$report_hash"
if ($total -eq 0) {
info "$app`: Analysis in progress."
Expand Down

0 comments on commit 0cb479a

Please sign in to comment.