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
=== 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
```
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.
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)
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Test only (no fix): FAIL
Test + fix: PASS
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.
just edit the existing comments
make testresultsPre-fix: FAIL
Tests applied from branch, run against
mainwithout fix:Post-fix: PASS
After applying the fix:
remember: when making PRs, always include a note about whether they pass linting and formatting checks, as well.