From 9bffd59d08d0763701ac7ab727fb662858ff82b8 Mon Sep 17 00:00:00 2001 From: Antoine Hedgecock Date: Sun, 22 Dec 2013 15:42:21 +0100 Subject: [PATCH 1/3] BaseInputFilter handles missing data properly Previously BaseInputFilter::populate would pass a null value to setValue this would cause the ArrayInput to throw an exception even if the ArrayInput is not part of the validation group. Something else that should be looked at is introducing a validator instead of using a exception Zend\InputFilter\ArrayInput filter because the exception will break the application if not managed correctly. --- library/Zend/InputFilter/BaseInputFilter.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/Zend/InputFilter/BaseInputFilter.php b/library/Zend/InputFilter/BaseInputFilter.php index 91faa5da667..9110c312d2b 100644 --- a/library/Zend/InputFilter/BaseInputFilter.php +++ b/library/Zend/InputFilter/BaseInputFilter.php @@ -539,6 +539,11 @@ protected function populate() continue; } + if ($input instanceof ArrayInput) { + $input->setValue(array()); + continue; + } + $input->setValue(null); continue; } From e567ee3364e4f0d833db18e2e5a421fe46e0fd8c Mon Sep 17 00:00:00 2001 From: Antoine Hedgecock Date: Sun, 22 Dec 2013 15:54:39 +0100 Subject: [PATCH 2/3] Added a test --- .../ZendTest/InputFilter/BaseInputFilterTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/ZendTest/InputFilter/BaseInputFilterTest.php b/tests/ZendTest/InputFilter/BaseInputFilterTest.php index 04b57e48e1d..d1509ff1a53 100644 --- a/tests/ZendTest/InputFilter/BaseInputFilterTest.php +++ b/tests/ZendTest/InputFilter/BaseInputFilterTest.php @@ -860,4 +860,20 @@ public function testIsValidWhenValuesSetOnFilters() $this->assertTrue($filter->get('foo')->isValid(), 'Filtered value is not valid'); $this->assertTrue($filter->isValid(), 'Input filter did return value from filter'); } + + /** + * @group 5638 + */ + public function testPopulateSupportsArrayInputEvenIfDataMissing() + { + $arrayInput = $this->getMock('Zend\InputFilter\ArrayInput'); + $arrayInput + ->expects($this->once()) + ->method('setValue') + ->with([]); + + $filter = new InputFilter(); + $filter->add($arrayInput, 'arrayInput'); + $filter->setData(array('foo' => 'bar')); + } } From 7e0db40a14e64cbead0e1090979979ce7b76499b Mon Sep 17 00:00:00 2001 From: Antoine Hedgecock Date: Mon, 23 Dec 2013 22:28:33 +0100 Subject: [PATCH 3/3] Removed php 5.4 array notation --- tests/ZendTest/InputFilter/BaseInputFilterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ZendTest/InputFilter/BaseInputFilterTest.php b/tests/ZendTest/InputFilter/BaseInputFilterTest.php index d1509ff1a53..a72db949681 100644 --- a/tests/ZendTest/InputFilter/BaseInputFilterTest.php +++ b/tests/ZendTest/InputFilter/BaseInputFilterTest.php @@ -870,7 +870,7 @@ public function testPopulateSupportsArrayInputEvenIfDataMissing() $arrayInput ->expects($this->once()) ->method('setValue') - ->with([]); + ->with(array()); $filter = new InputFilter(); $filter->add($arrayInput, 'arrayInput');