Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(search_bucket): set default and check type before using #6151

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions libexec/scoop-search.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,43 @@ function bin_match_json($json, $query) {

function search_bucket($bucket, $query) {
$apps = Get-ChildItem (Find-BucketDirectory $bucket) -Filter '*.json' -Recurse

$apps | ForEach-Object {
$filepath = $_.FullName

$json = try {
[System.Text.Json.JsonDocument]::Parse([System.IO.File]::ReadAllText($filepath))
} catch {
}
catch {
debug "Failed to parse manifest file: $filepath (error: $_)"
return
}

$name = $_.BaseName
$versionValue = "Unknown" # a default value

# check type of RootElement
if ($json.RootElement.ValueKind -eq [System.Text.Json.JsonValueKind]::Object) {
# try to get 'version' attribute
$version = [System.Text.Json.JsonElement]::new()
if ($json.RootElement.TryGetProperty('version', [ref] $version)) {
$versionValue = $version
}
}

if ($name -match $query) {
$list.Add([PSCustomObject]@{
Name = $name
Version = $json.RootElement.GetProperty('version')
Version = $versionValue
Source = $bucket
Binaries = ''
})
} else {
}
else {
$bin = bin_match_json $json $query
if ($bin) {
$list.Add([PSCustomObject]@{
Name = $name
Version = $json.RootElement.GetProperty('version')
Version = $versionValue
Source = $bucket
Binaries = $bin -join ' | '
})
Expand Down