fix: prevent subdomain-only route from overwriting hostname route#10211
fix: prevent subdomain-only route from overwriting hostname route#10211jalexiscv wants to merge 1 commit into
Conversation
Fixes codeigniter4#7214 When routes with both 'hostname' and 'subdomain' options are defined separately, a less specific subdomain-only route could overwrite a more specific hostname-matched route due to registration order. Changes: - Change 'elseif' to 'if' so both hostname and subdomain checks are independent. A route with both options now validates both. - Track matchedByHostname/matchedBySubdomain flags during registration - Add guard to prevent a route matched only by subdomain from overwriting an existing route that was registered with hostname, since hostname specificity should take precedence. Ref: codeigniter4#7214
|
Hi there, jalexiscv! 👋 Thank you for sending this PR! We expect the following in all Pull Requests (PRs).
Important We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works. If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md Sincerely, the mergeable bot 🤖 |
paulbalandan
left a comment
There was a problem hiding this comment.
Please add tests to prove the fix works. Also, add the fix to the changelog.
|
Closing due to no activity for over a month. We appreciate PRs sent but please ensure they’re complete or you’re prepared to complete them. Unfinished PRs simply add to maintainers’ review time and are not considerate of everyone’s time. |
Description
Fixes #7214 - Inconsistent hostname/subdomain limitation in Routing
Problem
When using
hostnameandsubdomainroute options, the precedence was inconsistent depending on whether they were on the same route or separate routes:Case 1: Same route (hostname took precedence - correct)
media.example.com → Media::index ✓
Case 2: Separate routes (subdomain incorrectly won)
media.example.com → All::index ✗ (should be Media::index)
Root Cause
Two issues:
elseifmeant routes with bothhostnameandsubdomainonly validated hostnameSolution
elseiftoif— bothhostnameandsubdomainare validated independentlymatchedByHostname/matchedBySubdomainflags during registrationChanges
One file:
system/Router/RouteCollection.phpRef: #7214
Closes #7214