Skip to content

fix: consistently decode URL path parameters#1100

Closed
wyf027 wants to merge 1 commit into
go-chi:masterfrom
wyf027:fix/urlparam-path-unescape
Closed

fix: consistently decode URL path parameters#1100
wyf027 wants to merge 1 commit into
go-chi:masterfrom
wyf027:fix/urlparam-path-unescape

Conversation

@wyf027

@wyf027 wyf027 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Use r.URL.EscapedPath() for route matching instead of preferring RawPath over Path
  • Decode URL path parameters via url.PathUnescape in Context.URLParam so callers always receive decoded values
  • Add regression test covering the inconsistent %20 encoding cases from URLParam sometimes returns URL-encoded variables #832

Test plan

  • go test ./...
  • TestURLParamPathUnescape/It's%20great and /It%20is%20great both return It is great / It's great
  • TestEscapedURLParams — encoded slashes in identifier decode to http://example.com/image.png

Fixes #832

URLParam returned percent-encoded values when RawPath was set on the
request, but decoded values otherwise. Use EscapedPath() for routing and
PathUnescape when reading URL parameters so callers always get decoded
values.

Fixes #832

Co-authored-by: Cursor <cursoragent@cursor.com>
@wyf027 wyf027 closed this by deleting the head repository Jun 23, 2026
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.

URLParam sometimes returns URL-encoded variables

1 participant