Skip to content

Commit 8b8b9fd

Browse files
fix(installer): resolve asset URL by tag, robust to minified API JSON
A single-line (minified) GitHub API response broke install.sh's line-based `grep browser_download_url | cut -d '"' -f 4`: it grabbed the 4th quote-field of the whole blob — the release object's API `url` — so self-update downloaded JSON and the magic-byte guard refused to install. Derive the tag (splitting on commas so it works pretty or minified) and construct the asset URL directly. install.ps1 uses a real JSON parser and was unaffected.
1 parent b97f567 commit 8b8b9fd

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ adheres to [Semantic Versioning](https://semver.org/). Work in progress lives un
88

99
## [Unreleased]
1010

11+
### Fixed
12+
- **installer**`install.sh` derives the release tag and constructs the asset URL deterministically
13+
(robust to minified API JSON), so `self-update` no longer downloads the release API object and
14+
refuses to install. `install.ps1` uses a JSON parser and was unaffected.
15+
1116
## [0.5.0] - 2026-06-30
1217

1318
### Added

install.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,21 @@ if ! RELEASE_JSON="$(curl -fsSL "$API_URL")"; then
3838
exit 1
3939
fi
4040

41-
DOWNLOAD_URL="$(printf '%s\n' "$RELEASE_JSON" | grep "browser_download_url.*$ASSET_NAME\"" | cut -d '"' -f 4)"
41+
# Extract the release tag, splitting on commas first so this works whether the API returns
42+
# pretty-printed OR minified JSON. A single-line (minified) response broke the old line-based
43+
# `grep | cut -f4`: it grabbed the 4th quote-field of the whole blob — the release object's API
44+
# `url` — and "downloaded" that JSON instead of the binary. Constructing the asset URL from the
45+
# tag avoids parsing the asset array entirely.
46+
TAG="$(printf '%s' "$RELEASE_JSON" | tr ',' '\n' | grep '"tag_name"' | head -n1 \
47+
| sed -E 's/.*"tag_name"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')"
4248

43-
if [ -z "$DOWNLOAD_URL" ]; then
44-
echo "Error: Could not find release asset for $OS_NAME $ARCH_NAME." >&2
49+
if [ -z "$TAG" ]; then
50+
echo "Error: could not determine the latest release tag from the GitHub API." >&2
4551
exit 1
4652
fi
4753

54+
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$TAG/$ASSET_NAME"
55+
4856
echo "Downloading from $DOWNLOAD_URL..."
4957
if ! curl -fL -o "$TMP_FILE" "$DOWNLOAD_URL"; then
5058
echo "Error: download failed from $DOWNLOAD_URL" >&2

0 commit comments

Comments
 (0)