Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ public function getRedirectCode(string $routeKey): int
* $route->resource('users');
* });
*
* @param string $name The name to group/prefix the routes with.
* @param array<string, mixed>|(callable(self): void) ...$params
* @param string $name The name to group/prefix the routes with.
* @param array<string, mixed>|(callable(static): void) ...$params
*
* @return void
*/
Expand Down
20 changes: 20 additions & 0 deletions tests/_support/Router/RouteCollectionSubclass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Support\Router;

use CodeIgniter\Router\RouteCollection;

final class RouteCollectionSubclass extends RouteCollection
{
}
33 changes: 33 additions & 0 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use Tests\Support\Controllers\Hello;
use Tests\Support\Router\RouteCollectionSubclass;

/**
* @internal
Expand Down Expand Up @@ -314,6 +315,38 @@ static function ($routes): void {
$this->assertSame($expected, $routes->getRoutes());
}

public function testGroupingPassesSubclassToNestedCallbacks(): void
{
$modules = new Modules();
$modules->enabled = false;
$config = new Routing();
$config->defaultNamespace = '\\';
$routes = new RouteCollectionSubclass(service('locator'), $modules, $config);
$routes->setHTTPVerb(Method::GET);

$routes->group('admin', ['namespace' => 'Admin', 'filter' => ['csrf']], function (RouteCollectionSubclass $group) use ($routes): void {
$this->assertSame($routes, $group);

$group->group('profile', ['filter' => ['honeypot']], function (RouteCollectionSubclass $nested) use ($routes): void {
$this->assertSame($routes, $nested);
$nested->get('show', 'Profile::show');
});

$group->get('dashboard', 'Dashboard::index');
});

$routes->get('home', 'Home::index');

$this->assertSame([
'admin/profile/show' => '\\Admin\\Profile::show',
'admin/dashboard' => '\\Admin\\Dashboard::index',
'home' => '\\Home::index',
], $routes->getRoutes(Method::GET));
$this->assertSame(['csrf', 'honeypot'], $routes->getFiltersForRoute('admin/profile/show'));
$this->assertSame(['csrf'], $routes->getFiltersForRoute('admin/dashboard'));
$this->assertFalse($routes->isFiltered('home'));
}

public function testGroupGetsSanitized(): void
{
$routes = $this->getCollector();
Expand Down
3 changes: 3 additions & 0 deletions user_guide_src/source/changelogs/v4.7.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Bugs Fixed
- **HTTP:** Fixed a bug where ``IncomingRequest`` did not read the request body when PHP's ``post_max_size`` was set to ``0`` or ``-1`` (unlimited).
- **HTTP:** Fixed a bug where ``IncomingRequest::isSecure()`` did not recognize ``https`` in the ``X-Forwarded-Proto`` header from a trusted proxy when the value contained uppercase letters or surrounding whitespace, or was represented as a single-element array.
- **HTTP:** Fixed stale ``$_REQUEST`` values after ``SiteURIFactory`` normalizes GET parameters, so ``Validation::withRequest()`` reads the normalized values while unrelated REQUEST entries are preserved.
- **Routing:** Corrected the PHPDoc callback type of ``RouteCollection::group()``
Comment thread
maniaba marked this conversation as resolved.
to preserve the concrete collection type, allowing callbacks typed to a
``RouteCollection`` subclass to pass static analysis.
Comment on lines +46 to +48

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also make it a one-liner?

- **Security:** Fixed a bug where a valid JSON request body that is not an object (for example a JSON array) was corrupted after CSRF verification when the token was sent via the ``X-CSRF-TOKEN`` header.

See the repo's
Expand Down
Loading