Skip to content

Always match routes against percent-encoded paths.#78

Merged
tigerwill90 merged 2 commits intomasterfrom
feat/rfc3986-path-matching
Feb 14, 2026
Merged

Always match routes against percent-encoded paths.#78
tigerwill90 merged 2 commits intomasterfrom
feat/rfc3986-path-matching

Conversation

@tigerwill90
Copy link
Collaborator

@tigerwill90 tigerwill90 commented Feb 14, 2026

Route matching previously relied on url.URL.RawPath for the request path, falling back to url.URL.Path when RawPath was empty. The problem is that Go only populates RawPath for certain encoded characters like %2F. A path like /café gets decoded into url.URL.Path as /café with RawPath left empty. This meant matching behavior was inconsistent depending on which characters happened to be encoded in the request.

This switches to url.URL.EscapedPath(), which always returns the closest representation to the raw request line. Matching now consistently operates on percent-encoded paths regardless of what characters are encoded. Hex digits in percent-encoding are normalized to uppercase (%c3%a9%C3%A9) to ensure equivalent encodings match the same route.

All routing entry points (ServeHTTP, Match, Lookup, and Sub) now use a shared routingPath() helper instead of calling c.Path() directly. This function calls EscapedPath() and normalizes any lowercase hex digits to uppercase when RawPath is set:

func routingPath(r *http.Request) string {
    if r.URL.RawPath == "" {
        return r.URL.EscapedPath()
    }
    return stringsutil.NormalizeHexUppercase(r.URL.EscapedPath())
}

When RawPath is empty, EscapedPath() already produces uppercase hex, so normalization is skipped.

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 95.34884% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
txn.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tigerwill90 tigerwill90 marked this pull request as ready for review February 14, 2026 13:04
@tigerwill90 tigerwill90 changed the title Always use EscapedPath Always match routes against percent-encoded paths. Feb 14, 2026
@tigerwill90 tigerwill90 merged commit e411077 into master Feb 14, 2026
4 checks passed
@tigerwill90 tigerwill90 deleted the feat/rfc3986-path-matching branch February 14, 2026 14:35
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.

2 participants