Skip to content

Commit e7a45bd

Browse files
Merge branch '4.2'
* 4.2: Revert "bug #30423 [Security] Rework firewall's access denied rule (dimabory)" [FrameworkBundle] minor: remove a typo from changelog [VarDumper] fix tests with ICU 64.1 [VarDumper][Ldap] relax some locally failing tests [Validator] #30192 Added the missing translations for the Tagalog ("tl") locale. Make MimeTypeExtensionGuesser case insensitive Fix get session when the request stack is empty [Routing] fix trailing slash redirection with non-greedy trailing vars [FrameworkBundle] decorate the ValidatorBuilder's translator with LegacyTranslatorProxy
2 parents 90b5a66 + 0e5719d commit e7a45bd

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

Matcher/Dumper/CompiledUrlMatcherTrait.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,22 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
136136
}
137137

138138
$hasTrailingVar = $trimmedPathinfo !== $pathinfo && $hasTrailingVar;
139+
140+
if ($hasTrailingVar && ($hasTrailingSlash || '/' !== substr($matches[\count($vars)], -1)) && preg_match($regex, $this->matchHost ? $host.'.'.$trimmedPathinfo : $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
141+
if ($hasTrailingSlash) {
142+
$matches = $n;
143+
} else {
144+
$hasTrailingVar = false;
145+
}
146+
}
147+
139148
if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
140149
if ($supportsRedirections && (!$requiredMethods || isset($requiredMethods['GET']))) {
141150
return $allow = $allowSchemes = [];
142151
}
143152
continue;
144153
}
145154

146-
if ($hasTrailingSlash && $hasTrailingVar && preg_match($regex, $this->matchHost ? $host.'.'.$trimmedPathinfo : $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
147-
$matches = $n;
148-
}
149-
150155
foreach ($vars as $i => $v) {
151156
if (isset($matches[1 + $i])) {
152157
$ret[$v] = $matches[1 + $i];

Matcher/UrlMatcher.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
158158

159159
$hasTrailingVar = $trimmedPathinfo !== $pathinfo && preg_match('#\{\w+\}/?$#', $route->getPath());
160160

161+
if ($hasTrailingVar && ($hasTrailingSlash || '/' !== substr($matches[(\count($matches) - 1) >> 1], -1)) && preg_match($regex, $trimmedPathinfo, $m)) {
162+
if ($hasTrailingSlash) {
163+
$matches = $m;
164+
} else {
165+
$hasTrailingVar = false;
166+
}
167+
}
168+
161169
if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
162170
if ($supportsTrailingSlash && (!$requiredMethods || \in_array('GET', $requiredMethods))) {
163171
return $this->allow = $this->allowSchemes = [];
@@ -166,10 +174,6 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
166174
continue;
167175
}
168176

169-
if ($hasTrailingSlash && $hasTrailingVar && preg_match($regex, $trimmedPathinfo, $m)) {
170-
$matches = $m;
171-
}
172-
173177
$hostMatches = [];
174178
if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
175179
continue;

Tests/Matcher/RedirectableUrlMatcherTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ public function testSlashAndVerbPrecedenceWithRedirection()
187187
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
188188
}
189189

190+
public function testNonGreedyTrailingRequirement()
191+
{
192+
$coll = new RouteCollection();
193+
$coll->add('a', new Route('/{a}', [], ['a' => '\d+']));
194+
195+
$matcher = $this->getUrlMatcher($coll);
196+
$matcher->expects($this->once())->method('redirect')->with('/123')->willReturn([]);
197+
198+
$this->assertEquals(['_route' => 'a', 'a' => '123'], $matcher->match('/123/'));
199+
}
200+
190201
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
191202
{
192203
return $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', [$routes, $context ?: new RequestContext()]);

0 commit comments

Comments
 (0)