Skip to content

Commit 7554783

Browse files
committed
Zero params should be passed through when routing. Fixes #2032
1 parent 95c46d5 commit 7554783

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

system/Router/Router.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,9 @@ public function autoRoute(string $uri)
568568
*/
569569
protected function validateRequest(array $segments): array
570570
{
571-
$segments = array_filter($segments);
571+
$segments = array_filter($segments, function ($segment) {
572+
return ! empty($segment) || ($segment !== '0' || $segment !== 0);
573+
});
572574
$segments = array_values($segments);
573575

574576
$c = count($segments);

tests/system/Router/RouterTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,4 +490,23 @@ public function testTranslateURIDashesForAutoRoute()
490490
}
491491

492492
//--------------------------------------------------------------------
493+
494+
/**
495+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/2032
496+
*/
497+
public function testAutoRouteMatchesZeroParams()
498+
{
499+
$router = new Router($this->collection, $this->request);
500+
501+
$router->autoRoute('myController/someMethod/0/abc');
502+
503+
$this->assertEquals('MyController', $router->controllerName());
504+
$this->assertEquals('someMethod', $router->methodName());
505+
506+
$expected = [
507+
'0',
508+
'abc',
509+
];
510+
$this->assertEquals($expected, $router->params());
511+
}
493512
}

0 commit comments

Comments
 (0)