From 6f97e82044c6c3cf74c912a684d78dd8a23a760f Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 10 Oct 2023 14:14:40 +0900 Subject: [PATCH 1/3] test: fix incorrect test The routes should be loaded before tests. --- tests/system/Helpers/URLHelper/MiscUrlTest.php | 1 + 1 file changed, 1 insertion(+) 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(); From e1e9a7b644b52e35a930361779c77e8d249e338a Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 10 Oct 2023 14:24:24 +0900 Subject: [PATCH 2/3] test: add test case for empty string --- .../system/Router/RouteCollectionReverseRouteTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) 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(); From 61f080e9392e1fb0a98ba451fd570d84507c0f39 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 10 Oct 2023 14:24:59 +0900 Subject: [PATCH 3/3] fix: reverse routing returns invalid route when '' is passed --- system/Router/RouteCollection.php | 4 ++++ 1 file changed, 4 insertions(+) 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)) {