Skip to content

fix: use url.JoinPath for list/diff command URLs#915

Merged
dangrondahl merged 2 commits into
mainfrom
913-fix-4-commands-still-use-fmtsprintf-for-url-construction-double-slash-bug
May 29, 2026
Merged

fix: use url.JoinPath for list/diff command URLs#915
dangrondahl merged 2 commits into
mainfrom
913-fix-4-commands-still-use-fmtsprintf-for-url-construction-double-slash-bug

Conversation

@dangrondahl

@dangrondahl dangrondahl commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the double-slash URL bug in four commands that were missed by #695. When --host or KOSLI_HOST has a trailing slash, the old fmt.Sprintf("%s/api/v2/...", global.Host, ...) pattern produced //api/v2/... URLs and 404 errors.

Affected commands:

  • kosli list artifacts
  • kosli list approvals
  • kosli list snapshots
  • kosli diff snapshots

All four now use url.JoinPath + url.Values, matching the pattern adopted across the rest of the codebase.

Closes #913

Test plan

  • make build succeeds
  • make lint passes
  • Manually verify kosli list artifacts --host https://app.kosli.com/ ... no longer returns 404

Four commands still built URLs with fmt.Sprintf("%s/api/v2/...",
global.Host, ...), producing double-slash URLs and 404s when --host
or KOSLI_HOST had a trailing slash. Switch to url.JoinPath with
url.Values for query params, matching the pattern adopted in #695.

Affected commands: list artifacts, list approvals, list snapshots,
diff snapshots.
@claude

claude Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Claude finished @dangrondahl's task in 1m 56s —— View job


Review of PR #915

  • Run static analysis (build, vet, mod tidy)
  • Read changed files and review diff
  • Check for consistency with codebase patterns
  • Post review findings

Static Analysis

All three checks pass cleanly:

  • go build ./... — compiles successfully
  • go vet ./... — no issues
  • go mod tidy — no drift in go.mod / go.sum

Code Review

This PR looks good. The changes are correct, consistent, and well-scoped. No issues found.

Correctness — All four commands now use url.JoinPath which properly handles trailing slashes on global.Host, fixing the double-slash bug. Query parameters are built via url.Values which handles encoding automatically (the old diffSnapshots.go code manually called url.QueryEscape on the snappish values — url.Values.Encode() does this internally, so the behavior is preserved).

Consistency — The url.JoinPath + base + "?" + params.Encode() pattern matches the dominant convention in the codebase (used in 6+ other files). The second commit switches from fmt.Sprintf to strconv.Itoa/strconv.FormatBool for query-param conversion, matching logEnvironment.go and other files. No remaining fmt.Sprintf URL construction patterns exist — grep confirms this PR catches the last four.

Improved safety in listArtifacts.go — The old code appended flow_name / repo_name via raw string concatenation (url + fmt.Sprintf("&repo_name=%s", ...)), which didn't escape special characters. The new code uses params.Set() which properly encodes values. Nice fix.

No test changes — The existing cmdTestCase-based tests for these commands exercise the HTTP path through httpfake stubs bound to fixed URL patterns. Since the tests already pass against the local server (which doesn't have a trailing-slash host), the fix is effectively tested by the integration test setup. Adding explicit trailing-slash test cases would strengthen coverage, but that's a nice-to-have, not a blocker.

No bugs, security issues, or performance concerns. Ship it.

Comment thread cmd/kosli/listApprovals.go Outdated
Comment thread cmd/kosli/listSnapshots.go Outdated
Align list/diff URL construction with the codebase convention
(logEnvironment.go, listTrails.go) by using strconv.Itoa /
strconv.FormatBool instead of fmt.Sprintf for int/bool query
parameters. Cosmetic; no behavior change.
@dangrondahl dangrondahl enabled auto-merge (squash) May 29, 2026 06:33
@dangrondahl dangrondahl merged commit 8040d80 into main May 29, 2026
20 checks passed
@dangrondahl dangrondahl deleted the 913-fix-4-commands-still-use-fmtsprintf-for-url-construction-double-slash-bug branch May 29, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: 4 commands still use fmt.Sprintf for URL construction (double-slash bug)

2 participants