Skip to content

Commit

Permalink
Merge pull request #3022 from Instrye/getPostGet
Browse files Browse the repository at this point in the history
Fix: index not exists, getPostGet and getGetPost should return null
  • Loading branch information
lonnieezell authored May 20, 2020
2 parents eebda65 + ee5f131 commit 6d019e5
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) : (isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : $this->getPost());
return isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : (isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : $this->getPost($index, $filter, $flags));
}

//--------------------------------------------------------------------
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) : (isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : $this->getGet());
return isset($_GET[$index]) ? $this->getGet($index, $filter, $flags) : (isset($_POST[$index]) ? $this->getPost($index, $filter, $flags) : $this->getGet($index, $filter, $flags));
}

//--------------------------------------------------------------------
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 @@ -463,4 +463,15 @@ public function testWithFalseBody()
$this->assertTrue($request->getBody() !== false);
$this->assertTrue($request->getBody() === null);
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/3020
*/
public function testGetPostIndexNotExists()
{
$_POST['TEST'] = 5;
$_GET['TEST'] = 3;
$this->assertNull($this->request->getPostGet('gc'));
$this->assertNull($this->request->getGetPost('gc'));
}
}

0 comments on commit 6d019e5

Please sign in to comment.