Skip to content

Commit 428edae

Browse files
Merge branch '4.1' into 4.2
* 4.1: [Serializer] fixed DateTimeNormalizer to maintain microseconds when a different timezone required [Routing] fix taking verb into account when redirecting [DI] Fix dumping expressions accessing single-use private services [WebProfilerBundle] Split form field heading
2 parents 12064b4 + 55e645b commit 428edae

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

Matcher/Dumper/PhpMatcherTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function match($pathinfo)
6767
throw new ResourceNotFoundException();
6868
}
6969

70-
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
70+
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
7171
{
7272
$allow = $allowSchemes = array();
7373
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
@@ -91,7 +91,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
9191
if ('/' === $pathinfo || $hasTrailingSlash === ('/' === $pathinfo[-1])) {
9292
// no-op
9393
} elseif ($this instanceof RedirectableUrlMatcherInterface) {
94-
return null;
94+
return $allow = $allowSchemes = array();
9595
} else {
9696
continue;
9797
}
@@ -140,7 +140,7 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
140140
}
141141
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
142142
if ($this instanceof RedirectableUrlMatcherInterface && (!$requiredMethods || isset($requiredMethods['GET']))) {
143-
return null;
143+
return $allow = $allowSchemes = array();
144144
}
145145
continue;
146146
}
@@ -176,6 +176,6 @@ private function doMatch(string $rawPathinfo, array &$allow = array(), array &$a
176176
throw new NoConfigurationException();
177177
}
178178

179-
return null;
179+
return array();
180180
}
181181
}

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/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
@@ -711,6 +711,20 @@ public function testSlashWithVerb()
711711
$this->assertSame(array('_route' => 'b'), $matcher->match('/bar/'));
712712
}
713713

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

0 commit comments

Comments
 (0)