Repository navigation
fix(Router): handle {locale} placeholder in redirect routes - #10761
Conversation
|
Thanks for fixing this, @banghamid! The root cause diagnosis is spot-on — using The logic is clean and safe for
LGTM! |
|
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() Let me know if anything else looks off. |
paulbalandan
left a comment
There was a problem hiding this comment.
Please add one localized redirect with an explicit non-default status, such as 301. An explicit status would verify that the lookup finds the configured value rather than falling back to 302.
{locale} placeholder in redirect routes
michalsn
left a comment
There was a problem hiding this comment.
Please add a changelog entry for this fix.
5494772 to
c4b5038
Compare
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: