Repository navigation
fix(node): keep the full query string on trailing slash redirects - #17961
Closed
Chy-Zaber-Bin-Zahid wants to merge 1 commit into
Closed
Chy-Zaber-Bin-Zahid wants to merge 1 commit into
Chy-Zaber-Bin-Zahid wants to merge 1 commit into
Conversation
The static file handler split the request URL on every `?`, so a query string containing a second `?` (for example `?redirect=/page?id=1`) was truncated in the 301 `Location` header. Split on the first `?` only. Claude-Session: https://claude.ai/code/session_01UVwZZjkMttKwiVX4Zhvkmi
🦋 Changeset detectedLatest commit: 1262c29 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Closed
1 task done
ematipico
requested changes
Sep 10, 2026
| // Only split on the first `?` so a query string that itself contains `?` is kept intact. | ||
| const queryIndex = fullUrl.indexOf('?'); | ||
| const urlPath = queryIndex === -1 ? fullUrl : fullUrl.slice(0, queryIndex); | ||
| const urlQuery = queryIndex === -1 ? undefined : fullUrl.slice(queryIndex + 1); |
Member
There was a problem hiding this comment.
This makes urlQuery undefined, which is a bug, because before this change, it was an empty string
Member
|
The bug has been fixed. Thank you though |
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.
Fixes #17962
Changes
@astrojs/node's static handler splits the request URL withfullUrl.split('?')and keeps only the first two parts, so a query string that itself contains a?is cut off when the trailing-slash redirect rebuilds theLocationheader.GET /one/?redirect=/x?y=1&z=2withtrailingSlash: 'never'→301 Location: /one?redirect=/x(expected/one?redirect=/x?y=1&z=2)GET /one?redirect=/x?y=1&z=2withtrailingSlash: 'always'→301 Location: /one/?redirect=/xThis affects any return URL, OAuth
state, or search URL carried in the query. The fix splits on the first?only, which is what RFC 3986 allows inside the query component.Changeset:
'@astrojs/node': patch.Testing
Added
Keeps a query string that contains a second?on redirectto all four existing redirect suites intest/trailing-slash.test.ts(always/never, with and withoutbase). All four fail before the change:and pass after it (38/38 in the file).
Docs
No docs change: this restores the documented behavior of the trailing-slash redirect, which is only meant to normalize the slash.