fix: getGetPost() and getPostGet() when index is null

This commit is contained in:
michalsn 2022-10-12 19:57:52 +02:00
parent 0aab05601c
commit b4c65a1663
No known key found for this signature in database
GPG Key ID: 9ACAA935C3776CE9
3 changed files with 27 additions and 1 deletions

View File

@ -613,6 +613,9 @@ class IncomingRequest extends Request
*/
public function getPostGet($index = null, $filter = null, $flags = null)
{
if ($index === null) {
return array_merge($this->getGet($index, $filter, $flags), $this->getPost($index, $filter, $flags));
}
// Use $_POST directly here, since filter_has_var only
// checks the initial POST data, not anything that might
// have been added since.
@ -630,6 +633,9 @@ class IncomingRequest extends Request
*/
public function getGetPost($index = null, $filter = null, $flags = null)
{
if ($index === null) {
return array_merge($this->getPost($index, $filter, $flags), $this->getGet($index, $filter, $flags));
}
// Use $_GET directly here, since filter_has_var only
// checks the initial GET data, not anything that might
// have been added since.

View File

@ -563,6 +563,26 @@ final class IncomingRequestTest extends CIUnitTestCase
$this->assertSame($_GET, $this->request->getGetPost());
}
public function testPostGetSecondStream()
{
$_GET['get'] = '3';
$this->assertSame($_GET, $this->request->getPostGet());
}
public function testGetPostSecondStream()
{
$_POST['post'] = '5';
$this->assertSame($_POST, $this->request->getGetPost());
}
public function testGetPostSecondStreams()
{
$_GET['get'] = '3';
$_POST['post'] = '5';
$this->assertSame(array_merge($_GET, $_POST), $this->request->getPostGet());
$this->assertSame(array_merge($_POST, $_GET), $this->request->getGetPost());
}
public function testWithFalseBody()
{
// Use `false` here to simulate file_get_contents returning a false value

View File

@ -36,6 +36,6 @@ none.
Bugs Fixed
**********
none.
- 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``.
See the repo's `CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_ for a complete list of bugs fixed.