From 87d476065df3ebed23f40199ec7d366ae8e81a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 21 Jun 2020 15:44:40 +0200 Subject: [PATCH] MAPG-69 fix routing to handle emptry string properly --- public/index.php | 2 +- src/Routing/RouteCollection.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/index.php b/public/index.php index d025071..24595aa 100644 --- a/public/index.php +++ b/public/index.php @@ -9,7 +9,7 @@ if (($pos = strpos($url, '?')) !== false) { } $url = rawurldecode($url); -$match = Container::$routeCollection->match($method, explode('/', $url)); +$match = Container::$routeCollection->match($method, $url == '' ? [] : explode('/', $url)); if ($match !== null) { list($route, $params) = $match; diff --git a/src/Routing/RouteCollection.php b/src/Routing/RouteCollection.php index c729c3e..d93007a 100644 --- a/src/Routing/RouteCollection.php +++ b/src/Routing/RouteCollection.php @@ -64,7 +64,7 @@ class RouteCollection throw new \Exception('Route already exists: ' . $id); } - $pattern = array_merge($this->groupStack, explode('/', $pattern)); + $pattern = array_merge($this->groupStack, $pattern === '' ? [] : explode('/', $pattern)); $route = new Route($id, $pattern, $handler); $groupNumber = count($pattern);