From 042525c67f0dd96d776c3ba1e0582a1e95457a24 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 12 Jun 2024 09:12:28 +0900 Subject: [PATCH 1/2] test: add test cases for routes with integer --- tests/system/Router/DefinedRouteCollectorTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/system/Router/DefinedRouteCollectorTest.php b/tests/system/Router/DefinedRouteCollectorTest.php index ca10a2fd7b51..7c493c028512 100644 --- a/tests/system/Router/DefinedRouteCollectorTest.php +++ b/tests/system/Router/DefinedRouteCollectorTest.php @@ -50,8 +50,10 @@ public function testCollect(): void { $routes = $this->createRouteCollection(); $routes->get('journals', 'Blogs'); + $routes->get('100', 'Home::index'); $routes->get('product/(:num)', 'Catalog::productLookupByID/$1'); $routes->get('feed', static fn () => 'A Closure route.'); + $routes->get('200', static fn () => 'A Closure route.'); $routes->view('about', 'pages/about'); $collector = new DefinedRouteCollector($routes); @@ -69,6 +71,12 @@ public function testCollect(): void 'name' => 'journals', 'handler' => '\App\Controllers\Blogs', ], + [ + 'method' => 'GET', + 'route' => '100', + 'name' => '100', + 'handler' => '\App\Controllers\Home::index', + ], [ 'method' => 'GET', 'route' => 'product/([0-9]+)', @@ -81,6 +89,12 @@ public function testCollect(): void 'name' => 'feed', 'handler' => '(Closure)', ], + [ + 'method' => 'GET', + 'route' => '200', + 'name' => '200', + 'handler' => '(Closure)', + ], [ 'method' => 'GET', 'route' => 'about', From 4e35d38b33070a06eee5f72cd207de2c62c6acda Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 12 Jun 2024 09:13:32 +0900 Subject: [PATCH 2/2] fix: TypeError in DefinedRouteCollector::collect() --- system/Router/DefinedRouteCollector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/Router/DefinedRouteCollector.php b/system/Router/DefinedRouteCollector.php index 8d4f1dc5b1b7..2452a141fa75 100644 --- a/system/Router/DefinedRouteCollector.php +++ b/system/Router/DefinedRouteCollector.php @@ -38,6 +38,10 @@ public function collect(): Generator $routes = $this->routeCollection->getRoutes($method); foreach ($routes as $route => $handler) { + // The route key should be a string, but it is stored as an array key, + // it might be an integer. + $route = (string) $route; + if (is_string($handler) || $handler instanceof Closure) { if ($handler instanceof Closure) { $view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false;