Skip to content

Commit b4c65a1

Browse files
committed
fix: getGetPost() and getPostGet() when index is null
1 parent 0aab056 commit b4c65a1

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

system/HTTP/IncomingRequest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,9 @@ public function getPost($index = null, $filter = null, $flags = null)
613613
*/
614614
public function getPostGet($index = null, $filter = null, $flags = null)
615615
{
616+
if ($index === null) {
617+
return array_merge($this->getGet($index, $filter, $flags), $this->getPost($index, $filter, $flags));
618+
}
616619
// Use $_POST directly here, since filter_has_var only
617620
// checks the initial POST data, not anything that might
618621
// have been added since.
@@ -630,6 +633,9 @@ public function getPostGet($index = null, $filter = null, $flags = null)
630633
*/
631634
public function getGetPost($index = null, $filter = null, $flags = null)
632635
{
636+
if ($index === null) {
637+
return array_merge($this->getPost($index, $filter, $flags), $this->getGet($index, $filter, $flags));
638+
}
633639
// Use $_GET directly here, since filter_has_var only
634640
// checks the initial GET data, not anything that might
635641
// have been added since.

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,26 @@ public function testGetPostEmpty()
563563
$this->assertSame($_GET, $this->request->getGetPost());
564564
}
565565

566+
public function testPostGetSecondStream()
567+
{
568+
$_GET['get'] = '3';
569+
$this->assertSame($_GET, $this->request->getPostGet());
570+
}
571+
572+
public function testGetPostSecondStream()
573+
{
574+
$_POST['post'] = '5';
575+
$this->assertSame($_POST, $this->request->getGetPost());
576+
}
577+
578+
public function testGetPostSecondStreams()
579+
{
580+
$_GET['get'] = '3';
581+
$_POST['post'] = '5';
582+
$this->assertSame(array_merge($_GET, $_POST), $this->request->getPostGet());
583+
$this->assertSame(array_merge($_POST, $_GET), $this->request->getGetPost());
584+
}
585+
566586
public function testWithFalseBody()
567587
{
568588
// Use `false` here to simulate file_get_contents returning a false value

user_guide_src/source/changelogs/v4.2.8.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ none.
3636
Bugs Fixed
3737
**********
3838

39-
none.
39+
- Fixed a bug when the ``CodeIgniter\HTTP\IncomingRequest::getPostGet()`` and ``CodeIgniter\HTTP\IncomingRequest::getGetPost()`` methods didn't return values from the other stream when ``index`` was set to ``null``.
4040

4141
See the repo's `CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_ for a complete list of bugs fixed.

0 commit comments

Comments
 (0)