Skip to content

Commit 842dcc6

Browse files
committed
fix: patch up optional dynamic params showing ""
1 parent c028707 commit 842dcc6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Router.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,11 +737,20 @@ public static function findRoute(
737737
return trim(substr($match[0][0], 0, $matches[$index + 1][0][1] - $match[0][1]), '/');
738738
}
739739

740+
// Temporary fix for optional parameters
741+
if (($match[0][1] ?? 1) === -1 && ($match[0][0] ?? null) === '') {
742+
return;
743+
}
744+
740745
// We have no following parameters: return the whole lot
741746
return isset($match[0][0]) ? trim($match[0][0], '/') : null;
742747
}, $matches, array_keys($matches));
743748

744749
$paramsWithSlash = array_filter($params, function ($param) {
750+
if (!$param) {
751+
return false;
752+
}
753+
745754
return strpos($param, '/') !== false;
746755
});
747756

@@ -860,6 +869,12 @@ private static function handle(?array $routes = null, bool $quitAfterRun = false
860869

861870
private static function invoke($handler, $params = [])
862871
{
872+
if (!empty($params)) {
873+
$params = array_filter($params, function ($param) {
874+
return $param !== null;
875+
});
876+
}
877+
863878
if (is_callable($handler)) {
864879
call_user_func_array(
865880
$handler,

0 commit comments

Comments
 (0)