Skip to content

Commit 97b9f45

Browse files
Merge branch '4.1' into 4.2
* 4.1: [Routing] fix trailing slash redirection calculate cache keys for property setters depending on the value updated VERSION for 2.8.48 update CONTRIBUTORS for 2.8.48 updated CHANGELOG for 2.8.48
2 parents 858d356 + 2c492d4 commit 97b9f45

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Matcher/Dumper/PhpMatcherTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
130130
continue;
131131
}
132132

133-
if ('/' === $pathinfo || $hasTrailingSlash === ('/' === $pathinfo[-1])) {
133+
if ('/' === $pathinfo || (!$hasTrailingSlash ? '/' !== $pathinfo[-1] || !preg_match($regex, substr($pathinfo, 0, -1), $n) || $m !== (int) $n['MARK'] : '/' === $pathinfo[-1])) {
134134
// no-op
135135
} elseif ($this instanceof RedirectableUrlMatcherInterface) {
136136
return null;

Matcher/UrlMatcher.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,13 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
160160
continue;
161161
}
162162

163-
if ($supportsTrailingSlash && $hasTrailingSlash !== ('/' === $pathinfo[-1])) {
164-
return;
163+
if ($supportsTrailingSlash) {
164+
if (!$hasTrailingSlash && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1))) {
165+
return;
166+
}
167+
if ($hasTrailingSlash && '/' !== $pathinfo[-1]) {
168+
return;
169+
}
165170
}
166171

167172
$hostMatches = array();

Tests/Matcher/UrlMatcherTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,15 @@ public function testHostWithDot()
683683
$this->assertEquals('b', $matcher->match('/bar/abc.123')['_route']);
684684
}
685685

686+
public function testSlashVariant()
687+
{
688+
$coll = new RouteCollection();
689+
$coll->add('a', new Route('/foo/{bar}', array(), array('bar' => '.*')));
690+
691+
$matcher = $this->getUrlMatcher($coll);
692+
$this->assertEquals('a', $matcher->match('/foo/')['_route']);
693+
}
694+
686695
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
687696
{
688697
return new UrlMatcher($routes, $context ?: new RequestContext());

0 commit comments

Comments
 (0)