diff --git a/src/App.php b/src/App.php index e1949d6d..703393d1 100755 --- a/src/App.php +++ b/src/App.php @@ -510,9 +510,12 @@ public function match(Request $request, bool $fresh = false): ?Route continue; } - // Check the paths have the same amount of segments - if (\substr_count($routeUrl, '/') !== \substr_count($url, '/')) { - continue; + // check for trailing wildcard + if (!str_ends_with($routeUrl, '/*')) { + // Check the paths have the same amount of segments + if (\substr_count($routeUrl, '/') !== \substr_count($url, '/')) { + continue; + } } \array_shift($this->matches); diff --git a/tests/AppTest.php b/tests/AppTest.php index fc08d535..8e325284 100755 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -407,14 +407,18 @@ public function providerRouteMatching(): array '1 separators' => [App::REQUEST_METHOD_GET, '/a/'], '2 separators' => [App::REQUEST_METHOD_GET, '/a/b'], '3 separators' => [App::REQUEST_METHOD_GET, '/a/b/c'], + 'trailing wildcard' => [App::REQUEST_METHOD_GET, '/wildcard/*', '/wildcard/lorem/ipsum'], + 'trailing wildcard - root' => [App::REQUEST_METHOD_GET, '/wildcard/*', '/wildcard'], ]; } /** * @dataProvider providerRouteMatching */ - public function testCanMatchRoute(string $method, string $path): void + public function testCanMatchRoute(string $method, string $path, string $expected = null): void { + $expected ??= $path; + switch ($method) { case App::REQUEST_METHOD_GET: $expected = App::get($path);