Skip to content

Commit

Permalink
fix trailing slash and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 9, 2020
1 parent a85f932 commit 3d58cd9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Illuminate/Routing/CompiledRouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,20 @@ public function refreshActionLookups()
*/
public function match(Request $request)
{
$trimmedRequest = clone $request;

$trimmedRequest->server->set(
'REQUEST_URI', rtrim($request->server->get('REQUEST_URI'), '/')
);

$matcher = new CompiledUrlMatcher(
$this->compiled, (new RequestContext)->fromRequest($request)
$this->compiled, (new RequestContext)->fromRequest($trimmedRequest)
);

$route = null;

try {
if ($result = $matcher->matchRequest($request)) {
if ($result = $matcher->matchRequest($trimmedRequest)) {
$route = $this->getByName($result['_route']);
}
} catch (ResourceNotFoundException | MethodNotAllowedException $e) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/Routing/CompiledRouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,15 @@ public function testRouteBindingsAreProperlySaved()
$this->assertSame(['user' => 'username', 'post' => 'slug'], $route->bindingFields());
}

public function testMatchingSlashedRoutes()
{
$this->routeCollection->add(
$route = $this->newRoute('GET', 'foo/bar', ['uses' => 'FooController@index', 'as' => 'foo'])
);

$this->assertSame('foo', $this->collection()->match(Request::create('/foo/bar/'))->getName());
}

/**
* Create a new Route object.
*
Expand Down

0 comments on commit 3d58cd9

Please sign in to comment.