8000 "app/console router:match" doesn't properly work with several routes with identical paths but differens host restrictions · Issue #8811 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

"app/console router:match" doesn't properly work with several routes with identical paths but differens host restrictions #8811

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

Closed
mymias opened this issue Aug 21, 2013 · 3 comments
Labels

Comments

@mymias
Copy link
mymias commented Aug 21, 2013

If I have several routes with same path but different host restriction, the command "router:match" won't find any matches for urls, that really matches second (or next) routes.

For example, I have routes

$routes->add('first', new Route(
    '/mypath/',
    array('_controller' => 'MainBundle:Info:first'),
    array(),
    array(),
    'some.example.com'
));

$routes->add('second', new Route(
    '/mypath/',
    array('_controller' => 'MainBundle:Info:second'),
    array(),
    array(),
    'another.example.com'
));

and if I try to execute command

php app/console router:match /mypath/

the command don't find any matches, if requested host not 'some.example.com'.

@mymias
Copy link
Author
mymias commented Aug 21, 2013

The cause of the Bug - in Symfony/Component/Routing/Matcher/TraceableUrlMatcher :: matchCollection().

Instead of "return true" in

        // check host requirement
        $hostMatches = array();
        if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
            $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);

            return true;
        }

should be "continue"

        // check host requirement
        $hostMatches = array();
        if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
            $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);

            continue;
        }

@Tobion
Copy link
Contributor
Tobion commented Aug 21, 2013

There seems to be something wrong with your setup.

  1. you have added 2 routes with the same name first. the second route will just override the previ 8000 ous.
  2. php app/console router:match first the argument is the path and not the name. so you mean /mypath/.

@mymias
Copy link
Author
mymias commented Aug 21, 2013

My apologies and thank you, Tobion! But it's just my mistake in this description because of rush. In real router config files we haven't these mistakes.

I've corrected my description of issue, thank you, Tobion, one more time.

fabpot added a commit that referenced this issue Dec 15, 2013
…s (karolsojko)

This PR was merged into the 2.3 branch.

Discussion
----------

[Routing] Fix router matching pattern against multiple hosts

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8811, #6744
| License       | MIT
| Doc PR        |

When you had a pattern that matched on multiple host then only the first one was displayed as "almost matching". Fixed router matching against the same pattern on multiple hosts so now it shows every "almost match" on different hosts.

Commits
-------

f727b22 [Routing] Fix router matching pattern against multiple hosts
@fabpot fabpot closed this as completed Dec 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
0