From 71d17cac8b1a72d7348ac196718e233f20f4623e Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Mon, 9 May 2016 20:42:30 -0400 Subject: [PATCH 1/2] Adding failing test for binding array with zero as key. --- tests/BindingTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/BindingTest.php b/tests/BindingTest.php index a334449..565ac01 100644 --- a/tests/BindingTest.php +++ b/tests/BindingTest.php @@ -205,6 +205,26 @@ public function testBindNestedArrayWithMissingKey() $this->assertEquals($expected, $result); } + public function testBindArrayWithZeroAsKey() + { + $array = [ + 'hotdog' => [ + 0 => 'Tube', + 1 => 'Steak', + ], + ]; + + $this->form->bind($array); + + $expected = ''; + $result = (string) $this->form->text('hotdog[0]'); + $this->assertEquals($expected, $result); + + $expected = ''; + $result = (string) $this->form->text('hotdog[1]'); + $this->assertEquals($expected, $result); + } + public function testBindNestedObject() { $object = json_decode(json_encode([ From 1cd183f77e44736df7cbfb0ccb8bda7a6fedf530 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Mon, 9 May 2016 20:51:14 -0400 Subject: [PATCH 2/2] Removing unnessessary array_filter call to pass tests. --- src/AdamWathan/Form/Binding/BoundData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdamWathan/Form/Binding/BoundData.php b/src/AdamWathan/Form/Binding/BoundData.php index 37d96ef..d6a9a50 100644 --- a/src/AdamWathan/Form/Binding/BoundData.php +++ b/src/AdamWathan/Form/Binding/BoundData.php @@ -23,7 +23,7 @@ public function data() protected function dotGet($dotKey, $default) { - $keyParts = array_filter(explode('.', $dotKey)); + $keyParts = explode('.', $dotKey); return $this->dataGet($this->data, $keyParts, $default); }