Skip to content

Commit b6acff1

Browse files
committed
[Routing] also add matched params for redirect due to trailing slash
1 parent ee51b0b commit b6acff1

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public function match($pathinfo)
3232
}
3333

3434
try {
35-
parent::match($pathinfo.'/');
35+
$parameters = parent::match($pathinfo.'/');
3636

37-
return $this->redirect($pathinfo.'/', null);
37+
return array_replace($parameters, $this->redirect($pathinfo.'/', isset($parameters['_route']) ? $parameters['_route'] : null));
3838
} catch (ResourceNotFoundException $e2) {
3939
throw $e;
4040
}

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,11 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
163163

164164
$status = $this->handleRouteRequirements($pathinfo, $name, $route);
165165

166-
if (self::ROUTE_MATCH === $status[0]) {
167-
$attributes = array_replace($matches, $hostMatches, (array) $status[1]);
168-
169-
return $this->mergeDefaults($attributes, $route->getDefaults());
170-
}
171-
172166
if (self::REQUIREMENT_MISMATCH === $status[0]) {
173167
continue;
174168
}
175169

176-
return $this->getAttributes($route, $name, array_replace($matches, $hostMatches));
170+
return $this->getAttributes($route, $name, array_replace($matches, $hostMatches, isset($status[1]) ? $status[1] : array()));
177171
}
178172
}
179173

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

+19-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testRedirectWhenNoSlash()
2323
$coll->add('foo', new Route('/foo/'));
2424

2525
$matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
26-
$matcher->expects($this->once())->method('redirect');
26+
$matcher->expects($this->once())->method('redirect')->will($this->returnValue(array()));
2727
$matcher->match('/foo');
2828
}
2929

@@ -68,7 +68,7 @@ public function testNoSchemaRedirectIfOnOfMultipleSchemesMatches()
6868
$matcher->match('/foo');
6969
}
7070

71-
public function testRedirectWithParams()
71+
public function testSchemeRedirectWithParams()
7272
{
7373
$coll = new RouteCollection();
7474
$coll->add('foo', new Route('/foo/{bar}', array(), array(), array(), '', array('https')));
@@ -78,8 +78,23 @@ public function testRedirectWithParams()
7878
->expects($this->once())
7979
->method('redirect')
8080
->with('/foo/baz', 'foo', 'https')
81-
->will($this->returnValue(array('_route' => 'foo')))
81+
->will($this->returnValue(array('redirect' => 'value')))
82+
;
83+
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'), $matcher->match('/foo/baz'));
84+
}
85+
86+
public function testSlashRedirectWithParams()
87+
{
88+
$coll = new RouteCollection();
89+
$coll->add('foo', new Route('/foo/{bar}/'));
90+
91+
$matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
92+
$matcher
93+
->expects($this->once())
94+
->method('redirect')
95+
->with('/foo/baz/', 'foo', null)
96+
->will($this->returnValue(array('redirect' => 'value')))
8297
;
83-
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz'), $matcher->match('/foo/baz'));
98+
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'), $matcher->match('/foo/baz'));
8499
}
85100
}

0 commit comments

Comments
 (0)