diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index 12fb1887e7d6..b7c04dfba89a 100755 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -427,7 +427,7 @@ public function getPostGet($index = null, $filter = null, $flags = null) // Use $_POST directly here, since filter_has_var only // checks the initial POST data, not anything that might // have been added since. - return isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : $this->getGet($index, $filter, $flags); + return isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : (isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : $this->getPost()); } //-------------------------------------------------------------------- @@ -446,7 +446,7 @@ public function getGetPost($index = null, $filter = null, $flags = null) // Use $_GET directly here, since filter_has_var only // checks the initial GET data, not anything that might // have been added since. - return isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : $this->getPost($index, $filter, $flags); + return isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : (isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : $this->getGet()); } //-------------------------------------------------------------------- diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index 9f748ba5e223..6457f92da6a6 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -423,4 +423,15 @@ public function testSpoofing() $this->assertEquals('wink', $this->request->getMethod()); } + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/2839 + */ + public function testGetPostEmpty() + { + $_POST['TEST'] = 5; + $_GET['TEST'] = 3; + $this->assertEquals($_POST, $this->request->getPostGet()); + $this->assertEquals($_GET, $this->request->getGetPost()); + } + }