Repository navigation
fix(middleware): preserve escaped paths in slash middleware - #3221
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3206.
Both trailing-slash middlewares now use the escaped path to decide whether to add or remove a literal slash and to construct RequestURI or Location. Forward mode keeps an existing
URL.RawPathsynchronized withURL.Path, so the router sees the updated path.Encoded separators stay path data, including leading
%2F/%5Cand a final%2Finside a parameter. Query strings are appended once per middleware.sanitizeURIis unchanged from master and still normalizes literal leading slashes/backslashes.Related: #3134 and #3207. This change covers both forwarding and redirecting.
Evidence
After: redirect-following and forward-mode tests reach the expected route with the original parameter, including
a%2Fas the final segment. Spaces, question marks, fragments, Unicode, query strings, and existing RawPath presence are covered.GOTOOLCHAIN=go1.27.4 go test -race ./...,go vet ./...,golint -set_exit_status ./..., and current staticcheck pass.Merge Danger
Door: two-way
Blast Radius: routing
Forwarding now keeps the escaped router path consistent. Redirects preserve escaped bytes; an encoded final slash remains parameter data rather than being removed or mistaken for an existing literal trailing slash.