Skip to content

Commit

Permalink
Merge pull request codeigniter4#2860 from Instrye/patch-1
Browse files Browse the repository at this point in the history
fix. getGetPost and getPostGet can't work in index empty
  • Loading branch information
lonnieezell authored Apr 21, 2020
2 parents 05e1734 + b9db954 commit a5c3c58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

//--------------------------------------------------------------------
Expand All @@ -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());
}

//--------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions tests/system/HTTP/IncomingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

0 comments on commit a5c3c58

Please sign in to comment.