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

Hotfix/non iterable inputfilter value #163

Merged
merged 6 commits into from
May 14, 2018
Merged

Hotfix/non iterable inputfilter value #163

merged 6 commits into from
May 14, 2018

Conversation

MadeRelevant
Copy link
Contributor

@MadeRelevant MadeRelevant commented Feb 14, 2018

Fixes issue #159

Currently, when you send a non-iterable value, non-null value to a nested input filter, it incorrectly raises an InvalidArgumentException. It should report as if all underlying fields are empty, and treat the value as an empty array.

@@ -523,6 +523,11 @@ protected function populate()
$value = $this->data[$name];

if ($input instanceof InputFilterInterface) {
// Fixes #159
if (! is_array($value) && !$value instanceof Traversable) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space after not (!) operator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing that out, I saw the travis build fail indeed. Didn't find time to fix it yet.

@MadeRelevant
Copy link
Contributor Author

@samsonasik everything ready to merge?

@samsonasik
Copy link
Contributor

I’m not maintainer ^^

@MadeRelevant
Copy link
Contributor Author

I’m not maintainer ^^

Lol, my bad

@MadeRelevant
Copy link
Contributor Author

@weierophinney ready to merge or do you need me something to change?

@@ -523,6 +523,11 @@ protected function populate()
$value = $this->data[$name];

if ($input instanceof InputFilterInterface) {
// Fixes #159
if (! is_array($value) && ! $value instanceof Traversable) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is a good fix. In case of invalid data, validation result can be valid in some situations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svycka

…validation result can be valid in some situations.

In this case there is no validation result. Only an exception.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@froschdesign I understand that this fixes exception just not sure if this will not cause other problems. For example, if this nested input filter is optional and invalid data was given it will replace an invalid object with [] and nested input filter will not be able to validate or return an error in case of invalid data.

But I don't know maybe that's not a problem since it was invalid anyway. If we ignore a problem that we can't return error messages for this then this is a good fix.

Copy link
Member

@froschdesign froschdesign Feb 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this nested input filter is optional

You can not set an input-filter as optional, therefore an exception is thrown.
Please look also at the related discussion: #159

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I am not sure about this so let's be it if this will be tested in all situations

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. for an optional input-filter you can use "Optional Input Filters".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am more concerned not about optional input filter but about its optional inputs but I don't know if this is bad

Copy link
Member

@froschdesign froschdesign Feb 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous link is for an entire input-filter and not for single (optional) input!

@svycka
Copy link
Contributor

svycka commented Feb 23, 2018

@MadeRelevant
Copy link
Contributor Author

MadeRelevant commented Feb 23, 2018

@svycka hmm, thats really weird, I ran the tests and it actually hits a breakpoint if I put it there.. Should be enough to prove it is touched and covered? When I run the tests with coverage it is for some strange reason not covered.. I have no clue why not while it reaches the breakpoint. I must be doing something wrong but not sure what, never had this before.

Any clues?

@svycka
Copy link
Contributor

svycka commented Feb 23, 2018

don't know but if the test fails without this fix and does not with it then it is ok

@MadeRelevant
Copy link
Contributor Author

MadeRelevant commented Feb 23, 2018

don't know but if the test fails without this fix and does not with it then it is ok

Yes it fails without it, just tested it. But still I think it is strange.. Bug in xdebug? PHPUnit reporter? Very weird..

@svycka
Copy link
Contributor

svycka commented Feb 23, 2018

@MadeRelevant oh I see whats wrong you have to move test to BaseInputFilterTest or add annotation like this:

    /**
     * @covers \Zend\InputFilter\BaseInputFilter
     */
    public function testNestedInputFilterShouldAllowNonArrayValueForData()
    {
// ...

@@ -523,6 +523,11 @@ protected function populate()
$value = $this->data[$name];

if ($input instanceof InputFilterInterface) {
// Fixes #159
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess comment is not required as it is covered with test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, coverage is fixed. I left the comment where it was. If it needs to be removed tell me.

@weierophinney weierophinney merged commit 62d0286 into zendframework:master May 14, 2018
weierophinney added a commit that referenced this pull request May 14, 2018
…lter-value

Hotfix/non iterable inputfilter value
weierophinney added a commit that referenced this pull request May 14, 2018
weierophinney added a commit that referenced this pull request May 14, 2018
weierophinney added a commit that referenced this pull request May 14, 2018
@weierophinney
Copy link
Member

Thanks, @MadeRelevant!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants