8000 Merge branch '4.2' · symfony/symfony@5ba4997 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ba4997

Browse files
Merge branch '4.2'
* 4.2: [Routing] fix greediness of trailing slash bumped Symfony version to 4.2.1 updated VERSION for 4.2.0 updated CHANGELOG for 4.2.0
2 parents 6da7afc + 799ad2e commit 5ba4997

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

CHANGELOG-4.2.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ in 4.2 minor versions.
77
To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash
88
To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v4.2.0...v4.2.1
99

10+
* 4.2.0 (2018-11-30)
11+
12+
* bug #29343 [Form] Handle all case variants of "nan" when parsing a number (mwhudson, xabbuh)
13+
* bug #29373 [Routing] fix trailing slash redirection (nicolas-grekas)
14+
* bug #29355 [PropertyAccess] calculate cache keys for property setters depending on the value (xabbuh)
15+
* bug #29369 [DI] fix combinatorial explosion when analyzing the service graph (nicolas-grekas)
16+
* bug #29349 [Debug] workaround opcache bug mutating "$this" !?! (nicolas-grekas)
17+
* bug #29344 Fixes sprintf(): Too few arguments in Translator (stephanedelprat)
18+
* bug #29318 [Console] Move back root exception to stack trace in verbose mode (chalasr)
19+
1020
* 4.2.0-RC1 (2018-11-26)
1121

1222
* bug #29332 [PropertyAccess] make cache keys encoding bijective (nicolas-grekas)

src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherTrait.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,20 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
130130
continue;
131131
}
132132

133-
if ('/' === $pathinfo || (!$hasTrailingSlash ? '/' !== $pathinfo[-1] || !preg_match($regex, substr($pathinfo, 0, -1), $n) || $m !== (int) $n['MARK'] : '/' === $pathinfo[-1])) {
134-
// no-op
135-
} elseif ($this instanceof RedirectableUrlMatcherInterface) {
136-
return null;
137-
} else {
138-
continue;
133+
if ('/' !== $pathinfo) {
134+
if ('/' === $pathinfo[-1]) {
135+
if (preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
136+
$matches = $n;
137+
} else {
138+
$hasTrailingSlash = true;
139+
}
140+
}
141+
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
142+
if ($this instanceof RedirectableUrlMatcherInterface && (!$requiredMethods || isset($requiredMethods['GET']))) {
143+
return null;
144+
}
145+
continue;
146+
}
139147
}
140148

141149
foreach ($vars as $i => $v) {

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,12 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
135135
foreach ($routes as $name => $route) {
136136
$compiledRoute = $route->compile();
137137
$staticPrefix = $compiledRoute->getStaticPrefix();
138+
$requiredMethods = $route->getMethods();
138139

139140
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
140141
if ('' === $staticPrefix || 0 === strpos($pathinfo, $staticPrefix)) {
141142
// no-op
142-
} elseif (!$supportsTrailingSlash) {
143+
} elseif (!$supportsTrailingSlash || ($requiredMethods && !\in_array('GET', $requiredMethods))) {
143144
continue;
144145
} elseif ('/' === $staticPrefix[-1] && substr($staticPrefix, 0, -1) === $pathinfo) {
145146
return;
@@ -161,11 +162,18 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
161162
}
162163

163164
if ($supportsTrailingSlash) {
164-
if (!$hasTrailingSlash && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1))) {
165-
return;
165+
if ('/' === $pathinfo[-1]) {
166+
if (preg_match($regex, substr($pathinfo, 0, -1), $m)) {
167+
$matches = $m;
168+
} else {
169+
$hasTrailingSlash = true;
170+
}
166171
}
167-
if ($hasTrailingSlash && '/' !== $pathinfo[-1]) {
168-
return;
172+
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
173+
if (!$requiredMethods || \in_array('GET', $requiredMethods)) {
174+
return;
175+
}
176+
continue;
169177
}
170178
}
171179

@@ -181,7 +189,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
181189
}
182190

183191
$hasRequiredScheme = !$route->getSchemes() || $route->hasScheme($this->context->getScheme());
184-
if ($requiredMethods = $route->getMethods()) {
192+
if ($requiredMethods) {
185193
// HEAD and GET are equivalent as per RFC
186194
if ('HEAD' === $method = $this->context->getMethod()) {
187195
$method = 'GET';

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,25 @@ public function testSlashVariant()
692692
$this->assertEquals('a', $matcher->match('/foo/')['_route']);
693693
}
694694

695+
public function testSlashVariant2()
696+
{
697+
$coll = new RouteCollection();
698+
$coll->add('a', new Route('/foo/{bar}/', array(), array('bar' => '.*')));
699+
700+
$matcher = $this->getUrlMatcher($coll);
701+
$this->assertEquals(array('_route' => 'a', 'bar' => 'bar'), $matcher->match('/foo/bar/'));
702+
}
703+
704+
public function testSlashWithVerb()
705+
{
706+
$coll = new RouteCollection();
707+
$coll->add('a', new Route('/{foo}', array(), array(), array(), '', array(), array('put', 'delete')));
708+
$coll->add('b', new Route('/bar/'));
709+
710+
$matcher = $this->getUrlMatcher($coll);
711+
$this->assertSame(array('_route' => 'b'), $matcher->match('/bar/'));
712+
}
713+
695714
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
696715
{
697716
return new UrlMatcher($routes, $context ?: new RequestContext());

0 commit comments

Comments
 (0)
0