Skip to content

Commit a5c3c58

Browse files
authored
Merge pull request #2860 from Instrye/patch-1
fix. getGetPost and getPostGet can't work in index empty
2 parents 05e1734 + b9db954 commit a5c3c58

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

system/HTTP/IncomingRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public function getPostGet($index = null, $filter = null, $flags = null)
427427
// Use $_POST directly here, since filter_has_var only
428428
// checks the initial POST data, not anything that might
429429
// have been added since.
430-
return isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : $this->getGet($index, $filter, $flags);
430+
return isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : (isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : $this->getPost());
431431
}
432432

433433
//--------------------------------------------------------------------
@@ -446,7 +446,7 @@ public function getGetPost($index = null, $filter = null, $flags = null)
446446
// Use $_GET directly here, since filter_has_var only
447447
// checks the initial GET data, not anything that might
448448
// have been added since.
449-
return isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : $this->getPost($index, $filter, $flags);
449+
return isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : (isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : $this->getGet());
450450
}
451451

452452
//--------------------------------------------------------------------

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,15 @@ public function testSpoofing()
423423
$this->assertEquals('wink', $this->request->getMethod());
424424
}
425425

426+
/**
427+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/2839
428+
*/
429+
public function testGetPostEmpty()
430+
{
431+
$_POST['TEST'] = 5;
432+
$_GET['TEST'] = 3;
433+
$this->assertEquals($_POST, $this->request->getPostGet());
434+
$this->assertEquals($_GET, $this->request->getGetPost());
435+
}
436+
426437
}

0 commit comments

Comments
 (0)