8000 merged branch canni/fix_traceable_matcher (PR #7009) · symfony/symfony@0f8d417 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f8d417

Browse files
committed
merged branch canni/fix_traceable_matcher (PR #7009)
This PR was merged into the 2.2 branch. Commits ------- 30b0c37 [Router] Fix TraceableUrlMatcher Discussion ---------- [BugFix][Router] Fix TraceableUrlMatcher TraceableUrlMatcher does not take care with new host route features | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #6744 | License | MIT | Doc PR | n/a
2 parents 180699a + 30b0c37 commit 0f8d417

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
7070
continue;
7171
}
7272

73+
// check host requirement
74+
$hostMatches = array();
75+
if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
76+
$this->addTrace(sprintf('Host "%s" does not match the required ("%s")', $route->getHost(), $this->context->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
77+
78+
return true;
79+
}
80+
7381
// check HTTP method requirement
7482
if ($req = $route->getRequirement('_method')) {
7583
// HEAD and GET are equivalent as per RFC

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,27 @@ public function test()
2424
$coll->add('foo', new Route('/foo', array(), array('_method' => 'POST')));
2525
$coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\d+')));
2626
$coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\w+', '_method' => 'POST')));
27+
$coll->add('bar2', new Route('/foo', array(), array(), array(), 'baz'));
28+
$coll->add('bar3', new Route('/foo1', array(), array(), array(), 'baz'));
2729

2830
$context = new RequestContext();
31+
$context->setHost('baz');
2932

3033
$matcher = new TraceableUrlMatcher($coll, $context);
3134
$traces = $matcher->getTraces('/babar');
32-
$this->assertEquals(array(0, 0, 0), $this->getLevels($traces));
35+
$this->assertEquals(array(0, 0, 0, 0, 0), $this->getLevels($traces));
3336

3437
$traces = $matcher->getTraces('/foo');
35-
$this->assertEquals(array(1, 0, 0), $this->getLevels($traces));
38+
$this->assertEquals(array(1, 0, 0, 2), $this->getLevels($traces));
3639

3740
$traces = $matcher->getTraces('/bar/12');
3841
$this->assertEquals(array(0, 2), $this->getLevels($traces));
3942

4043
$traces = $matcher->getTraces('/bar/dd');
41-
$this->assertEquals(array(0, 1, 1), $this->getLevels($traces));
44+
$this->assertEquals(array(0, 1, 1, 0, 0), $this->getLevels($traces));
45+
46+
$traces = $matcher->getTraces('/foo1');
47+
$this->assertEquals(array(0, 0, 0, 0, 2), $this->getLevels($traces));
4248

4349
$context->setMethod('POST');
4450
$traces = $matcher->getTraces('/foo');

0 commit comments

Comments
 (0)
0