Skip to content

Commit

Permalink
Merge pull request #1959 from MGatner/route-search-exempt-closures
Browse files Browse the repository at this point in the history
Prevent reverseRoute from searching closures
  • Loading branch information
lonnieezell authored May 14, 2019
2 parents e1b64da + 92ee0ca commit 2133346
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,12 @@ public function reverseRoute(string $search, ...$params)
{
$from = key($route['route']);
$to = $route['route'][$from];

// ignore closures
if (! is_string($to))
{
continue;
}

// Lose any namespace slash at beginning of strings
// to ensure more consistent match.
Expand Down
14 changes: 10 additions & 4 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,15 +947,21 @@ public function testReverseRoutingWithClosure()
{
$routes = $this->getCollector();

$routes->add(
'login', function () {
}
);
$routes->add('login', function() { });

$match = $routes->reverseRoute('login');

$this->assertEquals('/login', $match);
}

public function testReverseRoutingWithClosureNoMatch()
{
$routes = $this->getCollector();

$routes->add('login', function() { });

$this->assertFalse($routes->reverseRoute('foobar'));
}

//--------------------------------------------------------------------

Expand Down

0 comments on commit 2133346

Please sign in to comment.