Skip to content

Commit d5b5224

Browse files
committed
fix: $routes->group('/', ...) creates the route foo///bar
1 parent 53460ea commit d5b5224

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

system/Router/RouteCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ public function group(string $name, ...$params)
625625
// To register a route, we'll set a flag so that our router
626626
// so it will see the group name.
627627
// If the group name is empty, we go on using the previously built group name.
628-
$this->group = $name ? ltrim($oldGroup . '/' . $name, '/') : $oldGroup;
628+
$this->group = $name ? trim($oldGroup . '/' . $name, '/') : $oldGroup;
629629

630630
$callback = array_pop($params);
631631

tests/system/Router/RouteCollectionTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,34 @@ static function ($routes) {
375375
$this->assertSame($expected, $routes->getRoutes());
376376
}
377377

378+
public function testNestedGroupingWorksWithRootPrefix()
379+
{
380+
$routes = $this->getCollector();
381+
382+
$routes->add('verify/begin', '\VerifyController::begin');
383+
384+
$routes->group('admin', static function ($routes) {
385+
$routes->group(
386+
'/',
387+
static function ($routes) {
388+
$routes->add('users/list', '\Users::list');
389+
390+
$routes->group('delegate', static function ($routes) {
391+
$routes->add('foo', '\Users::foo');
392+
});
393+
}
394+
);
395+
});
396+
397+
$expected = [
398+
'verify/begin' => '\VerifyController::begin',
399+
'admin/users/list' => '\Users::list',
400+
'admin/delegate/foo' => '\Users::foo',
401+
];
402+
403+
$this->assertSame($expected, $routes->getRoutes());
404+
}
405+
378406
public function testHostnameOption()
379407
{
380408
$_SERVER['HTTP_HOST'] = 'example.com';

0 commit comments

Comments
 (0)