You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(Router): handle {locale} placeholder in redirect routes - #10761
Description
In Router::checkRoutes(), {locale} in $routeKey is replaced with '[^/]+' while the original route key registered in RouteCollection is preserved in $matchedKey. Previously, $this->collection->isRedirect($routeKey) and $this->collection->getRedirectCode($routeKey) were called with the modified $routeKey instead of $matchedKey.
As a result, redirect routes containing {locale} were never recognized as redirects:
Redirecting to a URI treated the target path as a controller name instead of throwing RedirectException.
Redirecting to a named route left $handler as an array and threw a TypeError at str_contains($handler, '::').
This PR:
Evaluates {locale} detection before checking for a redirect so unsupported locales are still rejected and $this->detectedLocale is populated.
Checks isRedirect($matchedKey) and getRedirectCode($matchedKey) using $matchedKey.
Replaces {locale} in $redirectTo with $this->detectedLocale when redirecting from a localized route.
Checklist:
Securely signed commits
Component(s) with PHPDoc blocks, only if necessary or adds value
Thanks for fixing this, @banghamid! The root cause diagnosis is spot-on — using $matchedKey correctly resolves both URI and named route redirects, and evaluating {locale} detection before checking for redirects is the right approach.
The logic is clean and safe for develop. A couple of suggestions regarding the tests:
Assert HTTP status code: testRedirectRoute() currently only checks expectExceptionMessage(). It would be great to also assert the status code (e.g., $this->expectExceptionCode(...)) so that the change to getRedirectCode($matchedKey) is explicitly covered.
Additional test cases (optional but nice to have):
A case combining {locale} with dynamic placeholders, e.g.:
Thanks for the review @gr8man! Good catch on the status code assertion, didn't notice testRedirectRoute() wasn't checking it yet.
Just pushed an update to add:
$this->expectExceptionCode(302) in testRedirectRoute()
the {locale} + (:num) dynamic placeholder cases
a test for useSupportedLocalesOnly(true) throwing PageNotFoundException on unsupported locales
Let me know if anything else looks off.
This branch has not been deployed
No deployments
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
bugVerified issues on the current code behavior or pull requests that will fix them
2 participants
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.
Description
In
Router::checkRoutes(),{locale}in$routeKeyis replaced with'[^/]+'while the original route key registered inRouteCollectionis preserved in$matchedKey. Previously,$this->collection->isRedirect($routeKey)and$this->collection->getRedirectCode($routeKey)were called with the modified$routeKeyinstead of$matchedKey.As a result, redirect routes containing
{locale}were never recognized as redirects:RedirectException.$handleras an array and threw aTypeErroratstr_contains($handler, '::').This PR:
{locale}detection before checking for a redirect so unsupported locales are still rejected and$this->detectedLocaleis populated.isRedirect($matchedKey)andgetRedirectCode($matchedKey)using$matchedKey.{locale}in$redirectTowith$this->detectedLocalewhen redirecting from a localized route.Checklist: