From 13e25407c4c6aa18645325280c0dcc7f0c958fb7 Mon Sep 17 00:00:00 2001 From: Divine Niiquaye Ibok Date: Mon, 7 Nov 2022 03:22:56 +0000 Subject: [PATCH] Fixed missing default value in regex issue --- src/RouteCompiler.php | 2 +- src/Traits/ResolverTrait.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RouteCompiler.php b/src/RouteCompiler.php index 316eee8..7d82c5c 100644 --- a/src/RouteCompiler.php +++ b/src/RouteCompiler.php @@ -53,7 +53,7 @@ final class RouteCompiler implements RouteCompilerInterface * - /{var=foo} - A required variable with default value * - /{var}[.{format:(html|php)=html}] - A required variable with an optional variable, a rule & default */ - private const COMPILER_REGEX = '~\{(\w+)(?:\:(.*?\}?))?(?:\=(.*?))?\}~i'; + private const COMPILER_REGEX = '~\{(\w+)(?:\:(.*?[\}=]?))?(?:\=(.*?))?\}~i'; /** * This regex is used to reverse a pattern path, matching required and options vars. diff --git a/src/Traits/ResolverTrait.php b/src/Traits/ResolverTrait.php index e90cb83..3b751b2 100644 --- a/src/Traits/ResolverTrait.php +++ b/src/Traits/ResolverTrait.php @@ -45,7 +45,7 @@ protected function assertRoute(string $method, UriInterface $uri, array &$route, if ($matched = 1 === \preg_match($hostsRegex.'i', $errors[2], $matches, \PREG_UNMATCHED_AS_NULL)) { foreach ($hostVar as $key => $value) { - $route['arguments'][$key] = $matches[$key] ?? $route['defaults'][$key] ?? $value; + $route['arguments'][$key] = $matches[$key] ?: $route['defaults'][$key] ?? $value; } } } elseif (isset($route['schemes']) && !isset($route['schemes'][$uri->getScheme()])) { @@ -114,7 +114,7 @@ protected function resolveCache(string $path, string $method, UriInterface $uri) $i = 0; foreach ($this->optimized[1][1][$o] ?? [] as $key => $value) { - $r['arguments'][$key] = $m[++$i] ?? $r['defaults'][$key] ?? $value; + $r['arguments'][$key] = $m[++$i] ?: $r['defaults'][$key] ?? $value; } return $r;