Skip to content

fix: refresh REQUEST after URI GET normalization - #10606

Open
rahul05ranjan wants to merge 2 commits into
codeigniter4:developfrom
rahul05ranjan:fix/request-refresh-after-uri-normalization
Open

rahul05ranjan wants to merge 2 commits into
codeigniter4:developfrom
rahul05ranjan:fix/request-refresh-after-uri-normalization

Conversation

@rahul05ranjan

Copy link
Copy Markdown

Description

Fixes #9872. SiteURIFactory can normalize $_GET after PHP has populated $_REQUEST, leaving stale query values for getVar() and Validation::withRequest(). This follows the direction agreed on in #10587: refresh REQUEST once during URI parsing while keeping getVar()'s existing lookup behavior.

Summary

SiteURIFactory parses the normalized query
  → update GET
  → refresh only REQUEST keys derived from GET, POST, or COOKIE
  → retain unrelated or independently changed REQUEST values

Superglobals::getRequestData() provides the merged source data in PHP's configured order. Both URI parsing paths use it before and after GET normalization. No general synchronization is added to setGetArray().

Evidence

  • Before: The two new SiteURI regressions fail on develop: the old query key remains in REQUEST, and code stays stale.
    After: SiteURIFactoryDetectRoutePathTest.php passes (34 tests, 42 assertions), including a withRequest() validation check and preservation of application-set values.
  • SuperglobalsTest.php passes (56 tests, 115 assertions); SiteURIFactoryTest.php passes (8 tests, 32 assertions).
  • File-scoped PHPStan and PHP CS Fixer checks pass on the changed PHP files. Full CI remains with GitHub Actions.

Merge Danger

Door: Two-way. Reverting the commit restores the previous request initialization behavior.

Blast Radius: Request initialization in the two SiteURIFactory URI parsing paths. An application-defined REQUEST value that is identical to its old merged source value cannot be distinguished from that source value; the refresh treats it as source-derived.

Checklist:

  • Securely signed commit (verified by GitHub)
  • Component PHPDoc added where it explains the merge and refresh behavior
  • Unit testing with >80% coverage (focused tests pass; coverage not measured locally)
  • User guide changelog updated; the existing getVar() reference remains accurate
  • Conforms to style guide (file-scoped PHP CS Fixer passes)

@carson-codeigniter4 carson-codeigniter4 Bot added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 9, 2026
@rahul05ranjan

Copy link
Copy Markdown
Author

@paulbalandan The new PR's workflows are waiting for approval to run. Could you approve them when you get to this review? Here's the PHPUnit run; the focused local results are in the PR description.

@paulbalandan
paulbalandan requested a review from michalsn October 9, 2026 12:50

@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.

Overall, I think this looks good.

Comment thread system/Superglobals.php
*
* @return array<string, request_items>
*/
public function getRequestData(?string $requestOrder = null): array

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 think this method should be marked as "internal".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new tests depend on the host’s request_order, and SiteURIFactory’s PHPDoc omits its new $_REQUEST side effect.

3 open findings
What changed in this PR

Fixes stale $_REQUEST values after URI query normalization while preserving custom entries.

Changes:

  • Adds configured GET/POST/COOKIE merging.
  • Refreshes source-derived REQUEST entries during URI parsing.
  • Adds regression tests and changelog documentation.

Base branch was unavailable; develop compatibility policy was applied. A focused PHP runtime probe passed; full validation remains with CI.

File Description
system/​Superglobals.php Adds merged request-data retrieval.
system/​HTTP/​SiteURIFactory.php Refreshes REQUEST after GET normalization.
tests/​system/​SuperglobalsTest.php Tests request merging semantics.
tests/​system/​HTTP/​SiteURIFactoryDetectRoutePathTest.php Tests URI normalization regressions.
user_guide_src/​source/​changelogs/​v4.7.5.rst Documents the fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


$factory = new SiteURIFactory(new App(), $superglobals);

$this->assertSame('ci/woot', $factory->detectRoutePath('QUERY_STRING'));
$this->superglobals->setGetArray(['get_key' => 'get_value']);
$this->superglobals->setPostArray(['post_key' => 'post_value']);

$data = $this->superglobals->getRequestData();
}

// Update our global GET for values likely to have been changed
// Refresh only the request values derived from superglobals after GET changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: getVar() behaves inconsistently with GET parameters

3 participants