From e6c03f473b957f23807e555dde1c3cb7275288a0 Mon Sep 17 00:00:00 2001 From: Tom van Beveren Date: Thu, 26 Sep 2024 10:33:54 +0200 Subject: [PATCH] Fixing a bug in case of a Optional Route Subpattern As described in https://github.com/leafsphp/router/issues/16#issue-2285682499 --- src/Router/Core.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Router/Core.php b/src/Router/Core.php index 4779ca6..6b5018d 100644 --- a/src/Router/Core.php +++ b/src/Router/Core.php @@ -378,7 +378,7 @@ private static function findRoute( // Extract the matched URL parameters (and only the parameters) $params = array_map(function ($match, $index) use ($matches) { // We have a following parameter: take the substring from the current param position until the next one's position (thank you PREG_OFFSET_CAPTURE) - if (isset($matches[$index + 1]) && isset($matches[$index + 1][0]) && is_array($matches[$index + 1][0])) { + if (isset($matches[$index + 1]) && isset($matches[$index + 1][0]) && $matches[$index + 1][0][1] != -1 && is_array($matches[$index + 1][0])) { return trim(substr($match[0][0], 0, $matches[$index + 1][0][1] - $match[0][1]), '/'); }