Skip to content

Commit 55e645b

Browse files
Merge branch '3.4' into 4.1
* 3.4: [Serializer] fixed DateTimeNormalizer to maintain microseconds when a different timezone required [Routing] fix taking verb into account when redirecting [WebProfilerBundle] Split form field heading
2 parents 7e99bbe + 19e4acc commit 55e645b

File tree

8 files changed

+60
-27
lines changed

8 files changed

+60
-27
lines changed

Matcher/Dumper/PhpMatcherDumper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ public function match($pathinfo)
161161
throw new ResourceNotFoundException();
162162
}
163163
164-
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
164+
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
165165

166166
EOF
167-
.$code."\n return null;\n }";
167+
.$code."\n return array();\n }";
168168
}
169169

170170
return " public function match(\$rawPathinfo)\n".$code."\n throw \$allow ? new MethodNotAllowedException(array_keys(\$allow)) : new ResourceNotFoundException();\n }";
@@ -565,7 +565,7 @@ private function compileSwitchDefault(bool $hasVars, bool $matchHost): string
565565
}\n" : '',
566566
$this->supportsRedirections ? "
567567
if (!\$requiredMethods || isset(\$requiredMethods['GET'])) {
568-
return null;
568+
return \$allow = \$allowSchemes = array();
569569
}" : ''
570570
);
571571

@@ -638,7 +638,7 @@ private function compileRoute(Route $route, string $name, bool $checkHost, bool
638638
%s;
639639
}\n\n",
640640
$hasTrailingSlash ? '!==' : '===',
641-
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return null' : 'break'
641+
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return $allow = $allowSchemes = array()' : 'break'
642642
);
643643
} elseif ($hasTrailingSlash) {
644644
$code .= sprintf("
@@ -648,14 +648,14 @@ private function compileRoute(Route $route, string $name, bool $checkHost, bool
648648
if ('/' !== \$pathinfo && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {
649649
\$matches = \$n;
650650
}\n\n",
651-
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return null' : 'break'
651+
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return $allow = $allowSchemes = array()' : 'break'
652652
);
653653
} else {
654654
$code .= sprintf("
655655
if ('/' !== \$pathinfo && '/' === \$pathinfo[-1] && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {
656656
%s;
657657
}\n\n",
658-
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return null' : 'break'
658+
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return $allow = $allowSchemes = array()' : 'break'
659659
);
660660
}
661661

Matcher/UrlMatcher.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
143143
} elseif (!$supportsTrailingSlash || ($requiredMethods && !\in_array('GET', $requiredMethods))) {
144144
continue;
145145
} elseif ('/' === $staticPrefix[-1] && substr($staticPrefix, 0, -1) === $pathinfo) {
146-
return;
146+
return $this->allow = $this->allowSchemes = array();
147147
} elseif ('/' === $pathinfo[-1] && substr($pathinfo, 0, -1) === $staticPrefix) {
148-
return;
148+
return $this->allow = $this->allowSchemes = array();
149149
} else {
150150
continue;
151151
}
@@ -171,7 +171,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
171171
}
172172
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
173173
if (!$requiredMethods || \in_array('GET', $requiredMethods)) {
174-
return;
174+
return $this->allow = $this->allowSchemes = array();
175175
}
176176
continue;
177177
}
@@ -212,6 +212,8 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
212212

213213
return $this->getAttributes($route, $name, array_replace($matches, $hostMatches, isset($status[1]) ? $status[1] : array()));
214214
}
215+
216+
return array();
215217
}
216218

217219
/**

Tests/Fixtures/dumper/url_matcher11.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function match($pathinfo)
5050
throw new ResourceNotFoundException();
5151
}
5252

53-
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
53+
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
5454
{
5555
$allow = $allowSchemes = array();
5656
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
@@ -129,7 +129,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
129129

130130
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
131131
if (!$requiredMethods || isset($requiredMethods['GET'])) {
132-
return null;
132+
return $allow = $allowSchemes = array();
133133
}
134134
break;
135135
}
@@ -167,6 +167,6 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
167167
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
168168
}
169169

170-
return null;
170+
return array();
171171
}
172172
}

Tests/Fixtures/dumper/url_matcher2.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function match($pathinfo)
5050
throw new ResourceNotFoundException();
5151
}
5252

53-
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
53+
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
5454
{
5555
$allow = $allowSchemes = array();
5656
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
@@ -94,7 +94,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
9494
if ('/' !== $pathinfo) {
9595
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
9696
if (!$requiredMethods || isset($requiredMethods['GET'])) {
97-
return null;
97+
return $allow = $allowSchemes = array();
9898
}
9999
break;
100100
}
@@ -183,7 +183,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
183183

184184
// baz4
185185
if ('/' !== $pathinfo[-1]) {
186-
return null;
186+
return $allow = $allowSchemes = array();
187187
}
188188
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
189189
$matches = $n;
@@ -249,7 +249,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
249249

250250
// foo2
251251
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
252-
return null;
252+
return $allow = $allowSchemes = array();
253253
}
254254

255255
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
@@ -260,7 +260,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
260260

261261
// foo3
262262
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
263-
return null;
263+
return $allow = $allowSchemes = array();
264264
}
265265

266266
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
@@ -300,7 +300,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
300300

301301
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
302302
if (!$requiredMethods || isset($requiredMethods['GET'])) {
303-
return null;
303+
return $allow = $allowSchemes = array();
304304
}
305305
break;
306306
}
@@ -338,6 +338,6 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
338338
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
339339
}
340340

341-
return null;
341+
return array();
342342
}
343343
}

Tests/Fixtures/dumper/url_matcher5.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function match($pathinfo)
5050
throw new ResourceNotFoundException();
5151
}
5252

53-
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
53+
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
5454
{
5555
$allow = $allowSchemes = array();
5656
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
@@ -86,7 +86,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
8686
if ('/' !== $pathinfo) {
8787
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
8888
if (!$requiredMethods || isset($requiredMethods['GET'])) {
89-
return null;
89+
return $allow = $allowSchemes = array();
9090
}
9191
break;
9292
}
@@ -137,7 +137,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
137137

138138
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
139139
if (!$requiredMethods || isset($requiredMethods['GET'])) {
140-
return null;
140+
return $allow = $allowSchemes = array();
141141
}
142142
break;
143143
}
@@ -175,6 +175,6 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
175175
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
176176
}
177177

178-
return null;
178+
return array();
179179
}
180180
}

Tests/Fixtures/dumper/url_matcher7.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function match($pathinfo)
5050
throw new ResourceNotFoundException();
5151
}
5252

53-
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
53+
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
5454
{
5555
$allow = $allowSchemes = array();
5656
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
@@ -82,7 +82,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
8282
if ('/' !== $pathinfo) {
8383
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
8484
if (!$requiredMethods || isset($requiredMethods['GET'])) {
85-
return null;
85+
return $allow = $allowSchemes = array();
8686
}
8787
break;
8888
}
@@ -149,7 +149,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
149149

150150
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
151151
if (!$requiredMethods || isset($requiredMethods['GET'])) {
152-
return null;
152+
return $allow = $allowSchemes = array();
153153
}
154154
break;
155155
}
@@ -187,6 +187,6 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
187187
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
188188
}
189189

190-
return null;
190+
return array();
191191
}
192192
}

Tests/Matcher/RedirectableUrlMatcherTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ public function testMissingTrailingSlashAndScheme()
170170
$matcher->match('/foo');
171171
}
172172

173+
public function testSlashAndVerbPrecedenceWithRedirection()
174+
{
175+
$coll = new RouteCollection();
176+
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('post')));
177+
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('get')));
178+
179+
$matcher = $this->getUrlMatcher($coll);
180+
$expected = array(
181+
'_route' => 'b',
182+
'customerId' => '123',
183+
);
184+
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons/'));
185+
186+
$matcher->expects($this->once())->method('redirect')->with('/api/customers/123/contactpersons/')->willReturn(array());
187+
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
188+
}
189+
173190
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
174191
{
175192
return $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($routes, $context ?: new RequestContext()));

Tests/Matcher/UrlMatcherTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,20 @@ public function testSlashWithVerb()
708708
$this->assertSame(array('_route' => 'b'), $matcher->match('/bar/'));
709709
}
710710

711+
public function testSlashAndVerbPrecedence()
712+
{
713+
$coll = new RouteCollection();
714+
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('post')));
715+
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('get')));
716+
717+
$matcher = $this->getUrlMatcher($coll);
718+
$expected = array(
719+
'_route' => 'b',
720+
'customerId' => '123',
721+
);
722+
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
723+
}
724+
711725
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
712726
{
713727
return new UrlMatcher($routes, $context ?: new RequestContext());

0 commit comments

Comments
 (0)