fix: sync \ after \ is updated in SiteURIFactory - #10587
rahul05ranjan wants to merge 5 commits into
Conversation
|
Hi there, @rahul05ranjan! 👋 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 |
a5e40a0 to
908744f
Compare
|
Hi. See #10205 |
|
Thanks for the pointer, @neznaika0 — I see now that #10205 took this same Based on the discussion in #9872, the preferred direction is to avoid mutating I'll drop the |
|
Reworked as discussed. The
Changes:
@neznaika0 @paulbalandan — does this match the direction you had in mind from #9872? |
SiteURIFactory updates \ (and \['QUERY_STRING']) when it detects the route path, but \ was left stale. Since PHP populates \ only once at the start of the request, getVar() (which reads \) returned outdated values, breaking \->withRequest() for GET parameters. Add Superglobals::syncRequest() to rebuild \ from \, \, and \ according to request_order/variables_order, and call it from SiteURIFactory after setGetArray(). Fixes codeigniter4#9872
$_REQUEST is populated only once at the start of the request, so it becomes stale when SiteURIFactory updates $_GET during URI parsing. getVar() previously read the stale $_REQUEST, breaking withRequest() for GET parameters. Instead of mutating $_REQUEST (the approach rejected in codeigniter4#10205), this change makes getVar() return a merged view of $_GET, $_POST, and $_COOKIE according to request_order, leaving $_REQUEST untouched. - Add Superglobals::getRequestData() returning the merged data. - Extract RequestTrait::fetchFromArray() to reuse the filtering logic. - Update getVar() to use getRequestData() + fetchFromArray(). - Revert the SiteURIFactory syncRequest() calls. - Update tests. Fixes codeigniter4#9872
8540948 to
7229261
Compare
- fetchFromArray() must be protected so IncomingRequest (a subclass) can call it. - Replace the short ternary in getRequestData() with explicit checks to satisfy the static analysis rules. - Drop the cookie assertion from the test since request_order defaults to GP (no cookies).
7229261 to
1bae1ba
Compare
|
Update: the rework is complete and all commits are now GPG-signed. Summary of the final state:
The Carson checks (signed-commits, no-merge-commits, pr-title-linter) are all passing. The remaining GitHub Actions workflows are showing @neznaika0 @paulbalandan — whenever you have a moment, could you take a look? Thanks! |
- Align phpdoc @PARAM annotations in RequestTrait::fetchFromArray. - Align match arm => operators in Superglobals::getRequestData.
neznaika0
left a comment
There was a problem hiding this comment.
I’m not very good at evaluating PR — I don’t know the exact direction in this matter. For myself, I’ve decided not to use $_REQUEST and getVar(). Do you know any specific cases where this is 100 % necessary? In most cases, it’s better to use an explicit data source (GET, POST, COOKIE).
Earlier, it was said that this is a system class (for tests), and for the user, you need to use Request.
Wait for the member answers.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical and moderate findings remain around request overrides and synchronizing $_REQUEST.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Updates request-variable retrieval so getVar() reflects current GET/POST/COOKIE data after URI parsing.
Changes:
- Adds merged request-data retrieval.
- Refactors reusable array-fetching logic.
- Updates request and validation tests.
| File | Summary |
|---|---|
tests/system/Validation/ValidationTest.php |
Adjusts validation fixtures to use POST data. |
tests/system/SuperglobalsTest.php |
Tests merged request-data behavior. |
tests/system/HTTP/IncomingRequestTest.php |
Updates request-variable fixtures. |
system/Superglobals.php |
Builds merged request data. |
system/HTTP/RequestTrait.php |
Extracts reusable array-fetching logic. |
system/HTTP/IncomingRequest.php |
Uses merged data in getVar(). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Make Superglobals::getRequestData() accept an optional request_order override so precedence and cookie branches can be tested deterministically. - Add tests for cookie merging, order-sensitive overwrite behavior, and unknown order types. - Add a regression test proving getVar() reflects $_GET changes even when $_REQUEST is stale.
|
@neznaika0 thanks for the review — and your instinct here is exactly right. To be clear, this PR doesn't add any new reliance on The direction matches what @paulbalandan suggested in #9872: instead of mutating On "100% necessary" cases: I agree — there's no case where |

Description
\SiteURIFactory\ updates \\ (and \['QUERY_STRING']) when it detects the route path, but \\ was left stale. Since PHP populates \\ only once at the start of the request, \getVar()\ (which reads \) returned outdated values, breaking \->withRequest()\ for GET parameters.
This PR adds \Superglobals::syncRequest(), which rebuilds \\ from \, \, and \\ according to the
equest_order\ (or \�ariables_order) ini setting, and calls it from \SiteURIFactory\ after \setGetArray()\ in both \parseRequestURI()\ and \parseQueryString().
This is a one-time synchronization at a single, well-defined point in the request lifecycle (as discussed in the issue), not permanent synchronization — matching standard PHP semantics where \\ is populated once.
Checklist:
Fixes: #9872
Testing: