diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 8a23264058cb..e484129a77b1 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -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)) { diff --git a/tests/system/Helpers/URLHelper/MiscUrlTest.php b/tests/system/Helpers/URLHelper/MiscUrlTest.php index 73ce680ea757..04da4f7352fe 100644 --- a/tests/system/Helpers/URLHelper/MiscUrlTest.php +++ b/tests/system/Helpers/URLHelper/MiscUrlTest.php @@ -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(); diff --git a/tests/system/Router/RouteCollectionReverseRouteTest.php b/tests/system/Router/RouteCollectionReverseRouteTest.php index d00e48e35b0d..02c8f4ba18f8 100644 --- a/tests/system/Router/RouteCollectionReverseRouteTest.php +++ b/tests/system/Router/RouteCollectionReverseRouteTest.php @@ -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();