Skip to content

refactor(Router): remove inappropriate input transformation from RouteCollection identifiers - #10517

Merged
paulbalandan merged 1 commit into
codeigniter4:4.8from
gr8man:fix/route-collection-esc-identifiers
Sep 6, 2026
Merged

paulbalandan merged 1 commit into
codeigniter4:4.8from
gr8man:fix/route-collection-esc-identifiers

Conversation

@gr8man

@gr8man gr8man commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Description
Removes inappropriate esc(strip_tags()) input transformations from RouteCollection default setters as well as resource() and presenter() controller options so that internal PHP identifiers are preserved without HTML entity conversion or tag stripping.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn left a comment

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.

I agree with the direction: HTML escaping does not belong on routing identifiers, especially since the Config\Routing constructor path already stores these values unescaped.

However, the PR currently demonstrates a cleanup rather than a patch-level bug. For valid UTF-8 PHP identifiers, the old code leaves permitted characters unchanged. Values such as Foo&Bar are not valid declared identifiers, and the tests only verify storage rather than a failed dispatch. Removing strip_tags() also makes the change broader than preventing entity encoding.

Please:

  • describe this as removing inappropriate input transformation and move it from Bugs Fixed to Changes;
  • update resource() and presenter() similarly, or explain why they are excluded. The $from handling in create() is a separate concern and should remain outside this PR.

Without a reproducible dispatch failure, I would target the 4.8 branch.

@gr8man
gr8man force-pushed the fix/route-collection-esc-identifiers branch from 4eed1b6 to 6c637ed Compare September 3, 2026 18:52
@gr8man gr8man changed the title fix(Router): remove esc(strip_tags()) from RouteCollection default setters refactor(Router): remove inappropriate input transformation from RouteCollection identifiers Sep 3, 2026
@gr8man
gr8man changed the base branch from develop to 4.8 September 3, 2026 18:52

@michalsn michalsn left a comment

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.

Please add a test similar to this:

#[DataProvider('provideGeneratedRouteMethods')]
public function testGeneratedRouteDoesNotTransformCustomController(string $method): void
{
    service('request')->setMethod(Method::GET);
    $routes = $this->getCollector();

    $routes->{$method}('photos', [
        'controller' => 'gallery&<b>archive</b>',
    ]);

    $this->assertSame(
        '\Gallery&<b>archive</b>::index',
        $routes->getRoutes()['photos'],
    );
}

public static function provideGeneratedRouteMethods(): iterable
{
    yield 'resource' => ['resource'];
    yield 'presenter' => ['presenter'];
}

To be safe, i would also want to add a section into https://github.com/codeigniter4/CodeIgniter4/blob/4.8/user_guide_src/source/installation/upgrade_480.rst - at the end of the "Breaking Changes", something like:

RouteCollection Identifier Transformation
=========================================

``RouteCollection`` no longer applies ``esc(strip_tags())`` to namespace, controller, and method values, including custom controllers passed to ``resource()`` and ``presenter()``.

Applications relying on HTML tags being stripped or special characters being HTML-encoded must preprocess these values before passing them to the router. Values originating from untrusted sources should be restricted to an explicit allowlist of permitted handlers.

Comment thread tests/system/Router/RouteCollectionTest.php
Comment thread user_guide_src/source/changelogs/v4.8.0.rst Outdated
@michalsn michalsn added the 4.8 PRs that target the `4.8` branch. label Sep 4, 2026
@gr8man
gr8man force-pushed the fix/route-collection-esc-identifiers branch from 6c637ed to 2f538c0 Compare September 5, 2026 19:45
@paulbalandan
paulbalandan merged commit 465504e into codeigniter4:4.8 Sep 6, 2026
57 checks passed
@paulbalandan paulbalandan added the refactor Pull requests that refactor code label Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch. refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants