Skip to content

Bug generating URL matcher for multiple routes differentiated by conditions #29106

Closed
@jaikdean

Description

@jaikdean

Symfony version(s) affected: 4.2.0-BETA1

Description
Creating two routes with the same URL path, but varying conditions no longer works. All of the routes end up using the conditions of the first route.

How to reproduce
Create two routes with the same path and different conditions. In the reproducer below, navigating to /test?conditionOne or /test?conditionTwo both run the first controller.

Bug reproducer: https://github.com/jaikdean/symfony-4.2-route-condition-bug

Additional context
In the reproducer above, the following class is generated when the cache is warmed. Note the switch statement with two case 0:.

<?php

use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;

/**
 * This class has been auto-generated
 * by the Symfony Routing Component.
 */
class srcApp_KernelDevDebugContainerUrlMatcher extends Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher
{
    use PhpMatcherTrait;

    public function __construct(RequestContext $context)
    {
        $this->context = $context;
        $this->staticRoutes = array(
            '/test' => array(
                array(array('_route' => 'condition_one', '_controller' => 'App\\Controller\\ExampleController::conditionOne'), null, array('GET' => 0), null, 0),
                array(array('_route' => 'condition_two', '_controller' => 'App\\Controller\\ExampleController::conditionTwo'), null, array('GET' => 0), null, 0),
            ),
        );
        $this->checkCondition = static function ($condition, $context, $request) {
            switch ($condition) {
                case 0: return $request->query->has("conditionOne");
                case 0: return $request->query->has("conditionTwo");
            }
        };
    }
}

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