Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix. getGetPost and getPostGet can't work in index empty #2860

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}

}