Skip to content

Routing: Tighten dynamic paths that use a forced trailing slash #733

Description

@g105b

This is a very obscure and minor bug, but it's worth tidying up as I've just managed to trigger it.

When app.force_trailing_slash is enabled, a static page can incorrectly execute _common.php from a competing dynamic path.

Given:

page/shop/
├── @category/
│   ├── _common.php
│   └── index.php
├── static-product-page.html
└── static-product-page.php

Requesting /shop/static-product-page/ produces a logic assembly containing both page/shop/static-product-page.php AND page/shop/@category/_common.php.

The dynamic _common.php should not execute because the concrete outer page should take precedence.

The static-precedence check constructs its glob using the unmodified URI:

glob($baseDir . $uriPath . ".*")

With a trailing slash, this searches for: page/shop/static-product-page/.* instead of the correct glob page/shop/static-product-page.*.

The concequence of this is that the static route is not detected during filtering and the dynamic magic file is also incorrectly matched.

A fix can be made with a tweak to DefaultRouter::pathMatcherFilter:

$staticUriPath = rtrim($uriPath, "/");

foreach (glob($baseDir . $staticUriPath . ".*") as $globMatch) {
    // existing filtering
}

Metadata

Metadata

Assignees

Labels

GT/RoutingRoute HTTP requests to the correct codeenhancementNon-breaking improvements to existing behaviour

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions