Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/163' into develop
Browse files Browse the repository at this point in the history
Forward port #163
  • Loading branch information
weierophinney committed May 14, 2018
2 parents 5eb35f8 + 0570a91 commit 5a78fbd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#163](https://github.com/zendframework/zend-inputfilter/pull/163) adds code to `BaseInputFilter::populate()` to detect non-iterable,
non-null values passed as a value for a composed input filter. Previously, these would trigger
an exception; they now instead result in an empty array being used to populate the
input filter, which will generally result in invalidation without causing an
exception.

- [#162](https://github.com/zendframework/zend-inputfilter/pull/162) fixes incorrect abstract service factory registration in `ConfigProvider`as per
the [latest documentation](https://docs.zendframework.com/zend-inputfilter/specs/#setup). In particular, it ensures that the `InputFilterAbstractFactory`
is registered under the `input_filters` configuration instead of the
Expand Down
5 changes: 5 additions & 0 deletions src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ protected function populate()
$value = $this->data[$name];

if ($input instanceof InputFilterInterface) {
// Fixes #159
if (! is_array($value) && ! $value instanceof Traversable) {
$value = [];
}

$input->setData($value);
continue;
}
Expand Down
18 changes: 18 additions & 0 deletions test/BaseInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,24 @@ public function testMerge()
);
}

public function testNestedInputFilterShouldAllowNonArrayValueForData()
{
$filter1 = new BaseInputFilter();
$nestedFilter = new BaseInputFilter();
$nestedFilter->add(new Input('nestedField1'));
$filter1->add($nestedFilter, 'nested');

// non scalar and non null value
$filter1->setData(['nested' => false]);
self::assertNull($filter1->getValues()['nested']['nestedField1']);

$filter1->setData(['nested' => 123]);
self::assertNull($filter1->getValues()['nested']['nestedField1']);

$filter1->setData(['nested' => new stdClass()]);
self::assertNull($filter1->getValues()['nested']['nestedField1']);
}

public function addMethodArgumentsProvider()
{
$inputTypes = $this->inputProvider();
Expand Down
1 change: 1 addition & 0 deletions test/InputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use ArrayIterator;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use stdClass;
use Zend\InputFilter\Factory;
use Zend\InputFilter\Input;
use Zend\InputFilter\InputFilter;
Expand Down

0 comments on commit 5a78fbd

Please sign in to comment.