8000 bug #9760 [Routing] Fix router matching pattern against multiple host… · symfony/symfony@f056ac1 · GitHub
[go: up one dir, main page]

Skip to content

Commit f056ac1

Browse files
committed
bug #9760 [Routing] Fix router matching pattern against multiple hosts (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
2 parents cb12401 + f727b22 commit f056ac1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
7575
if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
7676
$this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
7777

78-
return true;
78+
continue;
7979
}
8080

8181
// check HTTP method requirement

src/Symfony/Component/Routing/Tests/Matcher/TraceableUrlMatcherTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,37 @@ public function test()
5454
$this->assertEquals(array(0, 1, 2), $this->getLevels($traces));
5555
}
5656

57+
public function testMatchRouteOnMultipleHosts()
58+
{
59+
$routes = new RouteCollection();
60+
$routes->add('first', new Route(
61+
'/mypath/',
62+
array('_controller' => 'MainBundle:Info:first'),
63+
array(),
64+
array(),
65+
'some.example.com'
66+
));
67+
68+
$routes->add('second', new Route(
69+
'/mypath/',
70+
array('_controller' => 'MainBundle:Info:second'),
71+
array(),
72+
array(),
73+
'another.example.com'
74+
));
75+
76+
$context = new RequestContext();
77+
$context->setHost('baz');
78+
79+
$matcher = new TraceableUrlMatcher($routes, $context);
80+
81+
$traces = $matcher->getTraces('/mypath/');
82+
$this->assertEquals(
83+
array(TraceableUrlMatcher::ROUTE_ALMOST_MATCHES, TraceableUrlMatcher::ROUTE_ALMOST_MATCHES),
84+
$this->getLevels($traces)
85+
);
86+
}
87+
5788
public function getLevels($traces)
5889
{
5990
$levels = array();

0 commit comments

Comments
 (0)
0