Skip to content

Commit 06c3328

Browse files
wesmclaude
andauthored
Fix install.sh version parsing with minified JSON (#62)
## Summary - Fix `get_latest_version()` in `scripts/install.sh` extracting the wrong JSON field when the GitHub API returns minified (single-line) JSON - The `grep | cut` pipeline matched the entire JSON line and extracted the `"url"` value instead of `"tag_name"`, producing a nonsensical download URL - Use `grep -o` to extract only the `"tag_name":"..."` substring before passing to `cut`, which works regardless of JSON formatting Fixes #61 ## Test plan - [ ] Run `curl -fsSL https://api.github.com/repos/wesm/agentsview/releases/latest | grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | cut -d'"' -f4` and verify it returns the tag (e.g. `v0.8.0`) - [ ] Pipe minified single-line JSON through the same pipeline and verify correct extraction - [ ] Run `curl -fsSL https://agentsview.io/install.sh | bash` after merge and verify successful install 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 25239ea commit 06c3328

2 files changed

Lines changed: 69 additions & 2 deletions

File tree

scripts/install.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ download() {
5555

5656
get_latest_version() {
5757
local url="https://api.github.com/repos/${REPO}/releases/latest"
58+
local json
5859
if command -v curl &>/dev/null; then
59-
curl -fsSL "$url" | grep '"tag_name"' | head -1 | cut -d'"' -f4
60+
json=$(curl -fsSL "$url")
6061
elif command -v wget &>/dev/null; then
61-
wget -qO- "$url" | grep '"tag_name"' | head -1 | cut -d'"' -f4
62+
json=$(wget -qO- "$url")
63+
else
64+
return 1
6265
fi
66+
echo "$json" \
67+
| grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' \
68+
| head -1 \
69+
| cut -d'"' -f4
6370
}
6471

6572
verify_checksum() {

scripts/install_test.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
# Tests for install.sh version parsing logic
3+
set -euo pipefail
4+
5+
PASS=0
6+
FAIL=0
7+
8+
assert_eq() {
9+
local desc="$1" expected="$2" actual="$3"
10+
if [ "$expected" = "$actual" ]; then
11+
echo " PASS: $desc"
12+
PASS=$((PASS + 1))
13+
else
14+
echo " FAIL: $desc"
15+
echo " expected: '$expected'"
16+
echo " actual: '$actual'"
17+
FAIL=$((FAIL + 1))
18+
fi
19+
}
20+
21+
parse_tag_name() {
22+
echo "$1" \
23+
| grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' \
24+
| head -1 \
25+
| cut -d'"' -f4
26+
}
27+
28+
echo "=== get_latest_version parsing ==="
29+
30+
# Pretty-printed JSON (typical curl response)
31+
PRETTY='{
32+
"url": "https://api.github.com/repos/wesm/agentsview/releases/291105519",
33+
"tag_name": "v0.8.0",
34+
"name": "v0.8.0"
35+
}'
36+
assert_eq "pretty-printed JSON" "v0.8.0" "$(parse_tag_name "$PRETTY")"
37+
38+
# Minified JSON (the case that caused #61)
39+
MINIFIED='{"url":"https://api.github.com/repos/wesm/agentsview/releases/291105519","assets_url":"https://api.github.com/repos/wesm/agentsview/releases/291105519/assets","tag_name":"v0.8.0","name":"v0.8.0"}'
40+
assert_eq "minified JSON" "v0.8.0" "$(parse_tag_name "$MINIFIED")"
41+
42+
# tag_name before url field
43+
REORDERED='{"tag_name":"v1.2.3","url":"https://api.github.com/repos/wesm/agentsview/releases/1"}'
44+
assert_eq "tag_name before url" "v1.2.3" "$(parse_tag_name "$REORDERED")"
45+
46+
# Extra whitespace around colon
47+
SPACED='{ "tag_name" : "v2.0.0" }'
48+
assert_eq "extra whitespace" "v2.0.0" "$(parse_tag_name "$SPACED")"
49+
50+
# Pre-release version
51+
PRERELEASE='{"tag_name":"v0.9.0-rc1","name":"v0.9.0-rc1"}'
52+
assert_eq "pre-release version" "v0.9.0-rc1" "$(parse_tag_name "$PRERELEASE")"
53+
54+
# No tag_name field (API error / rate limit)
55+
NO_TAG='{"message":"API rate limit exceeded"}'
56+
assert_eq "missing tag_name returns empty" "" "$(parse_tag_name "$NO_TAG")"
57+
58+
echo
59+
echo "Results: $PASS passed, $FAIL failed"
60+
[ "$FAIL" -eq 0 ]

0 commit comments

Comments
 (0)