Skip to content

CompiledUrlGenerator & UrlGenerator - Passes wrong locale as parameter #35915

@christoph-pflueger

Description

@christoph-pflueger

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:

  1. DefaultController with one route
  2. The prefix has been configured in config/routes/annotations.yaml
  3. One template to show the bug

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy