-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
CompiledUrlGenerator & UrlGenerator - Passes wrong locale as parameter #35915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm going to look at this one. |
Status: works for me but can be improved IMO, this is a case of misconfiguration. The problem is not on the generation side. Requirements and defaults are added automatically when using i18n routes. A generated i18n route is supposed to have the right However, I guess we can improve the DX.
We can't do this because we need to be able to generate a |
|
…rement from being overridden (fancyweb) This PR was merged into the 4.4 branch. Discussion ---------- [Routing] Prevent localized routes _locale default & requirement from being overridden | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #35915 | License | MIT | Doc PR | - When we have configured a localized route, its default _locale and _locale requirement should not be modified to ensure it works as expected. Commits ------- 096dc0a [Routing] Prevent localized routes _locale default & requirement from being overridden
Symfony version(s) affected: All
Description
When using internationalized routes with _locale as a prefix, the UrlGenerator creates routes with the correct route name but the wrong _locale.
For example:
When there are two routes available:
en: /bug
de: /fehler
Then the CompiledUrlGenerator and UrlGenerator generate /en/fehler for the German route when en is the default locale.
How to reproduce
https://github.com/git-chrisp/symfony-routing-bug
Visit the path /de/fehler. It should show /de/fehler but shows /en/fehler instead as en is the default locale.
This repository is the website skeleton with the following additions:
Possible Solution
In line 59 of the CompiledUrlGenerator (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Generator/CompiledUrlGenerator.php):
$parameters['_locale'] = $locale ?? $defaults['_locale'];
Same has to be done in the UrlGenerator: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Generator/UrlGenerator.php
Additional context
Please correct me if I'm wrong or my proposed fix doesn't work. Otherwise, I'd gladly create a pull request.
The text was updated successfully, but these errors were encountered: