E57D [Routing] Fix router matching pattern against multiple hosts · symfony/symfony@f727b22 · GitHub
[go: up one dir, main page]

Skip to content

Commit f727b22

Browse files
author
karolsojko
committed
[Routing] Fix router matching pattern against multiple hosts
1 parent cbce472 commit f727b22

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