Skip to content

Commit 3d58cd9

Browse files
committed
fix trailing slash and add test
1 parent a85f932 commit 3d58cd9

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Illuminate/Routing/CompiledRouteCollection.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,20 @@ public function refreshActionLookups()
109109
*/
110110
public function match(Request $request)
111111
{
112+
$trimmedRequest = clone $request;
113+
114+
$trimmedRequest->server->set(
115+
'REQUEST_URI', rtrim($request->server->get('REQUEST_URI'), '/')
116+
);
117+
112118
$matcher = new CompiledUrlMatcher(
113-
$this->compiled, (new RequestContext)->fromRequest($request)
119+
$this->compiled, (new RequestContext)->fromRequest($trimmedRequest)
114120
);
115121

116122
$route = null;
117123

118124
try {
119-
if ($result = $matcher->matchRequest($request)) {
125+
if ($result = $matcher->matchRequest($trimmedRequest)) {
120126
$route = $this->getByName($result['_route']);
121127
}
122128
} catch (ResourceNotFoundException | MethodNotAllowedException $e) {

tests/Integration/Routing/CompiledRouteCollectionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,15 @@ public function testRouteBindingsAreProperlySaved()
422422
$this->assertSame(['user' => 'username', 'post' => 'slug'], $route->bindingFields());
423423
}
424424

425+
public function testMatchingSlashedRoutes()
426+
{
427+
$this->routeCollection->add(
428+
$route = $this->newRoute('GET', 'foo/bar', ['uses' => 'FooController@index', 'as' => 'foo'])
429+
);
430+
431+
$this->assertSame('foo', $this->collection()->match(Request::create('/foo/bar/'))->getName());
432+
}
433+
425434
/**
426435
* Create a new Route object.
427436
*

0 commit comments

Comments
 (0)