Skip to content

Commit

Permalink
Merge pull request #142 from ebenezerdon/fix-preserve-numeric-segments
Browse files Browse the repository at this point in the history
Fix: preserve numeric segments in path matching
  • Loading branch information
TorstenDittmann authored Sep 9, 2024
2 parents cc880ec + b332eec commit 60c659e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor/
/.idea/
*.cache
*.cache
.history
.phpactor.json
2 changes: 1 addition & 1 deletion src/Http/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static function match(string $method, string $path): Route|null
return null;
}

$parts = array_values(array_filter(explode('/', $path)));
$parts = array_values(array_filter(explode('/', $path), fn ($segment) => $segment !== ''));
$length = count($parts) - 1;
$filteredParams = array_filter(self::$params, fn ($i) => $i <= $length);

Expand Down
1 change: 1 addition & 0 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testCanMatchUrlWithPlaceholder(): void
$this->assertEquals($routeBlogAuthorsComments, Router::match(Http::REQUEST_METHOD_GET, '/blog/authors/comments'));
$this->assertEquals($routeBlogPost, Router::match(Http::REQUEST_METHOD_GET, '/blog/test'));
$this->assertEquals($routeBlogPostComments, Router::match(Http::REQUEST_METHOD_GET, '/blog/test/comments'));
$this->assertEquals($routeBlogPostCommentsSingle, Router::match(Http::REQUEST_METHOD_GET, '/blog/test/comments/0'));
$this->assertEquals($routeBlogPostCommentsSingle, Router::match(Http::REQUEST_METHOD_GET, '/blog/test/comments/:comment'));
}

Expand Down

0 comments on commit 60c659e

Please sign in to comment.