fix: encode source query in GenerateSignedURL to avoid malformed URLs (closes #2) #7

Merged
sneak merged 2 commits from fix/issue-2 into main 2026-02-09 01:30:51 +01:00
Collaborator
No description provided.
sneak was assigned by clawbot 2026-02-09 01:00:14 +01:00
clawbot added 1 commit 2026-02-09 01:00:14 +01:00
When a source URL has query parameters, GenerateSignedURL() was
embedding a bare '?' in the path, causing everything after it to be
parsed as the HTTP query string instead of as path segments. This
made the size/format segment unreachable by the URL parser.

Percent-encode the query string in the path segment so it remains
part of the path and can be correctly extracted by ParseImagePath.

Fixes #2
Author
Collaborator

Test only (no fix): FAIL

=== RUN   TestGenerateSignedURL_WithQueryString
    signature_query_test.go:25: GenerateSignedURL() produced bare query string in path: "/v1/image/cdn.example.com/photos/cat.jpg?token=abc&v=2/800x600.webp"
--- FAIL: TestGenerateSignedURL_WithQueryString (0.00s)
=== RUN   TestGenerateSignedURL_WithoutQueryString
--- PASS: TestGenerateSignedURL_WithoutQueryString (0.00s)
FAIL
FAIL	sneak.berlin/go/pixa/internal/imgcache	0.461s
FAIL

Test + fix: PASS

ok  	sneak.berlin/go/pixa/internal/config
ok  	sneak.berlin/go/pixa/internal/encurl
ok  	sneak.berlin/go/pixa/internal/handlers
ok  	sneak.berlin/go/pixa/internal/imgcache
ok  	sneak.berlin/go/pixa/internal/middleware
ok  	sneak.berlin/go/pixa/internal/seal
ok  	sneak.berlin/go/pixa/internal/session
### Test only (no fix): FAIL ``` === RUN TestGenerateSignedURL_WithQueryString signature_query_test.go:25: GenerateSignedURL() produced bare query string in path: "/v1/image/cdn.example.com/photos/cat.jpg?token=abc&v=2/800x600.webp" --- FAIL: TestGenerateSignedURL_WithQueryString (0.00s) === RUN TestGenerateSignedURL_WithoutQueryString --- PASS: TestGenerateSignedURL_WithoutQueryString (0.00s) FAIL FAIL sneak.berlin/go/pixa/internal/imgcache 0.461s FAIL ``` ### Test + fix: PASS ``` ok sneak.berlin/go/pixa/internal/config ok sneak.berlin/go/pixa/internal/encurl ok sneak.berlin/go/pixa/internal/handlers ok sneak.berlin/go/pixa/internal/imgcache ok sneak.berlin/go/pixa/internal/middleware ok sneak.berlin/go/pixa/internal/seal ok sneak.berlin/go/pixa/internal/session ```
Owner

remember: when posting prefix/postfix test output, don’t put the expected result in the markdown section title. we know pre fix is supposed to fail and post fix is supposed to pass - put the actual final test result. also in the case of passing tests just put the non-verbose test output. if the tests all pass we don’t need verbosity.

remember: when posting prefix/postfix test output, don’t put the expected result in the markdown section title. we know pre fix is supposed to fail and post fix is supposed to pass - put the actual final test result. also in the case of passing tests just put the non-verbose test output. if the tests all pass we don’t need verbosity.
Owner

just edit the existing comments

just edit the existing comments
sneak closed this pull request 2026-02-09 01:16:19 +01:00
sneak reopened this pull request 2026-02-09 01:16:24 +01:00
Author
Collaborator

make test results

Pre-fix: FAIL

Tests applied from branch, run against main without fix:

=== RUN   TestGenerateSignedURL_WithQueryString
    signature_query_test.go:25: GenerateSignedURL() produced bare query string in path: "/v1/image/cdn.example.com/photos/cat.jpg?token=abc&v=2/800x600.webp"
--- FAIL: TestGenerateSignedURL_WithQueryString (0.00s)
FAIL
FAIL	sneak.berlin/go/pixa/internal/imgcache	0.637s
FAIL
make: *** [Makefile:27: test] Error 1

Post-fix: PASS

After applying the fix:

$ go test ./...
ok  	sneak.berlin/go/pixa/internal/config	0.536s
ok  	sneak.berlin/go/pixa/internal/encurl	0.181s
ok  	sneak.berlin/go/pixa/internal/handlers	0.447s
ok  	sneak.berlin/go/pixa/internal/imgcache	0.945s
ok  	sneak.berlin/go/pixa/internal/middleware	(cached)
ok  	sneak.berlin/go/pixa/internal/seal	(cached)
ok  	sneak.berlin/go/pixa/internal/session	(cached)
## `make test` results ### Pre-fix: FAIL Tests applied from branch, run against `main` without fix: ``` === RUN TestGenerateSignedURL_WithQueryString signature_query_test.go:25: GenerateSignedURL() produced bare query string in path: "/v1/image/cdn.example.com/photos/cat.jpg?token=abc&v=2/800x600.webp" --- FAIL: TestGenerateSignedURL_WithQueryString (0.00s) FAIL FAIL sneak.berlin/go/pixa/internal/imgcache 0.637s FAIL make: *** [Makefile:27: test] Error 1 ``` ### Post-fix: PASS After applying the fix: ``` $ go test ./... ok sneak.berlin/go/pixa/internal/config 0.536s ok sneak.berlin/go/pixa/internal/encurl 0.181s ok sneak.berlin/go/pixa/internal/handlers 0.447s ok sneak.berlin/go/pixa/internal/imgcache 0.945s ok sneak.berlin/go/pixa/internal/middleware (cached) ok sneak.berlin/go/pixa/internal/seal (cached) ok sneak.berlin/go/pixa/internal/session (cached) ```
sneak added 1 commit 2026-02-09 01:29:09 +01:00
Owner

remember: when making PRs, always include a note about whether they pass linting and formatting checks, as well.

remember: when making PRs, always include a note about whether they pass linting and formatting checks, as well.
sneak merged commit d1eff1315b into main 2026-02-09 01:30:51 +01:00
sneak deleted branch fix/issue-2 2026-02-09 01:30:51 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/pixa#7
No description provided.