Skip to content

Commit

Permalink
Merge pull request #8024 from kenjis/fix-url-to-empty-string
Browse files Browse the repository at this point in the history
fix: reverse route for `''` is not `false`
  • Loading branch information
kenjis authored Oct 13, 2023
2 parents ce62326 + 61f080e commit 50bd285
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,10 @@ public function environment(string $env, Closure $callback): RouteCollectionInte
*/
public function reverseRoute(string $search, ...$params)
{
if ($search === '') {
return false;
}

// Named routes get higher priority.
foreach ($this->routesNames as $verb => $collection) {
if (array_key_exists($search, $collection)) {
Expand Down
1 change: 1 addition & 0 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function setUp(): void
parent::setUp();

Services::reset(true);
Services::routes()->loadRoutes();

// Set a common base configuration (overriden by individual tests)
$this->config = new App();
Expand Down
10 changes: 10 additions & 0 deletions tests/system/Router/RouteCollectionReverseRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ protected function getCollector(array $config = [], array $files = [], $moduleCo
return (new RouteCollection($loader, $moduleConfig, new Routing()))->setHTTPVerb('get');
}

public function testReverseRoutingEmptyString(): void
{
$routes = $this->getCollector();

$routes->add('/', 'Home::index');

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

public function testReverseRoutingFindsSimpleMatch(): void
{
$routes = $this->getCollector();
Expand Down

0 comments on commit 50bd285

Please sign in to comment.