Skip to content

Commit

Permalink
Allow full stops in route parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice Williams committed May 20, 2024
1 parent 04b1d05 commit c51742c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build
composer.lock
docs
vendor
.phpunit.result.cache
3 changes: 3 additions & 0 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ private function createAltoRoutes()

$this->altoRouter = new AltoRouter();
$this->altoRouter->setBasePath($this->basePath);
$this->altoRouter->addMatchTypes([
'' => '[^/]++',
]);
$this->altoRoutesCreated = true;

foreach ($this->routes as $route) {
Expand Down
17 changes: 17 additions & 0 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,23 @@ public function params_are_parsed_and_passed_into_callback_function()
$this->assertSame(1, $count);
}

/** @test */
public function params_may_contain_full_stops()
{
$request = new ServerRequest([], [], '/posts/a.b.c', 'GET');
$router = new Router;

$route = $router->get('/posts/{postId}', function ($params) use (&$count) {
$count++;

$this->assertInstanceOf(RouteParams::class, $params);
$this->assertSame('a.b.c', $params->postId);
});
$router->match($request);

$this->assertSame(1, $count);
}

/** @test */
public function params_are_parsed_and_passed_into_callback_function_when_surrounded_by_whitespace()
{
Expand Down

0 comments on commit c51742c

Please sign in to comment.