diff options
author | Andrey Andreev <narf@devilix.net> | 2018-07-22 15:38:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-22 15:38:42 +0200 |
commit | 29b2ac04223c701fdd21c7c900d0d65dc6fd6b9c (patch) | |
tree | 56274462d05b9e1da712decf316362f6148c5870 | |
parent | d0d4548c4b6917a3e389fb97acbc6123e2060ae2 (diff) | |
parent | 82584355c38abd18b00878c8f860ea4e7e60bf12 (diff) |
Merge pull request #5531 from tianhe1986/develop_input_array_notation
Input: considering nested array keys in `get_post` and `post_get`
-rw-r--r-- | system/core/Input.php | 10 | ||||
-rw-r--r-- | tests/codeigniter/core/Input_test.php | 34 |
2 files changed, 38 insertions, 6 deletions
diff --git a/system/core/Input.php b/system/core/Input.php index 34f080899..7f5f2e91d 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -212,9 +212,8 @@ class CI_Input { */ public function post_get($index, $xss_clean = FALSE) { - return isset($_POST[$index]) - ? $this->post($index, $xss_clean) - : $this->get($index, $xss_clean); + $output = $this->post($index, $xss_clean); + return isset($output) ? $output : $this->get($index, $xss_clean); } // -------------------------------------------------------------------- @@ -228,9 +227,8 @@ class CI_Input { */ public function get_post($index, $xss_clean = FALSE) { - return isset($_GET[$index]) - ? $this->get($index, $xss_clean) - : $this->post($index, $xss_clean); + $output = $this->get($index, $xss_clean); + return isset($output) ? $output : $this->post($index, $xss_clean); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 80cb9a740..07a99e136 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -90,6 +90,23 @@ class Input_test extends CI_TestCase { // -------------------------------------------------------------------- + public function test_post_get_array_notation() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo']['bar'] = 'baz'; + $barArray = array('bar' => 'baz'); + + $this->assertEquals('baz', $this->input->get_post('foo[bar]')); + $this->assertEquals($barArray, $this->input->get_post('foo[]')); + $this->assertNull($this->input->get_post('foo[baz]')); + + $this->assertEquals('baz', $this->input->post_get('foo[bar]')); + $this->assertEquals($barArray, $this->input->post_get('foo[]')); + $this->assertNull($this->input->post_get('foo[baz]')); + } + + // -------------------------------------------------------------------- + public function test_get_post() { $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -100,6 +117,23 @@ class Input_test extends CI_TestCase { // -------------------------------------------------------------------- + public function test_get_post_array_notation() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['foo']['bar'] = 'baz'; + $barArray = array('bar' => 'baz'); + + $this->assertEquals('baz', $this->input->get_post('foo[bar]')); + $this->assertEquals($barArray, $this->input->get_post('foo[]')); + $this->assertNull($this->input->get_post('foo[baz]')); + + $this->assertEquals('baz', $this->input->post_get('foo[bar]')); + $this->assertEquals($barArray, $this->input->post_get('foo[]')); + $this->assertNull($this->input->post_get('foo[baz]')); + } + + // -------------------------------------------------------------------- + public function test_cookie() { $_COOKIE['foo'] = 'bar'; |