Skip to content

Commit a4ca60f

Browse files
Copilotshenxianpeng
andcommitted
Use defensive jq command to prevent array indexing errors
Co-authored-by: shenxianpeng <[email protected]>
1 parent f44b895 commit a4ca60f

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

lib/utils.bash

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ fetch_all_assets() {
5050
response=$(curl -s -H "Accept: application/vnd.github.v3+json" \
5151
"https://api.github.com/repos/${GH_REPO}/releases")
5252

53-
# Debug: Log response type and content for debugging
54-
log "DEBUG: Response type: $(echo "$response" | jq -r 'type' 2>/dev/null || echo 'invalid-json')"
55-
log "DEBUG: Response preview: $(echo "$response" | head -c 200)"
56-
5753
# Check if response is valid JSON
5854
if ! echo "$response" | jq empty 2>/dev/null; then
5955
fail "Failed to fetch releases from GitHub API. Invalid JSON response."
@@ -74,10 +70,9 @@ fetch_all_assets() {
7470
fail "No releases found in repository ${GH_REPO}."
7571
fi
7672

77-
log "DEBUG: About to extract assets from response"
78-
79-
# Extract assets from the first release safely
80-
echo "$response" | jq -r '.[0].assets[]? | "\(.name) \(.browser_download_url)"'
73+
# Extract assets from the first release safely with built-in type checking
74+
# This provides additional protection against edge cases
75+
echo "$response" | jq -r 'if type == "array" and length > 0 then .[0].assets[]? | "\(.name) \(.browser_download_url)" else empty end'
8176
}
8277

8378
validate_platform() {

0 commit comments

Comments
 (0)