Skip to content

Commit

Permalink
Fixed missing default value in regex issue
Browse files Browse the repository at this point in the history
  • Loading branch information
divineniiquaye committed Nov 7, 2022
1 parent 7bc80b5 commit 13e2540
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/RouteCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/ResolverTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()])) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 13e2540

Please sign in to comment.