Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix the constructor's type-autodetection accepts wrong parameters #4351

Closed
wants to merge 1 commit into from

2 participants

@noopable
$validator = new \Zend\Validator\NotEmpty(array('translatorEnabled' => true));
var_dump($validator->getType());
var_dump($validator->isValid(''));

expects
493
false

but actually
1
true.

because if 'type' is not found in $options, the autodetection compares bool(true) to string(constants), it is true. And autodetector set 'type' true.
So, in_array 's third parameter should be true.

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4351'
Close #4351
8eb91c7
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4351' into develop
Forward port #4351
e1f5d89
@noopable noopable deleted the noopable:patch-validator-notempty branch
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge pull request zendframework/zf2#4351 from noopable/patch-validat…
…or-notempty

fix the constructor's type-autodetection accepts wrong parameters
63a3d48
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge branch 'hotfix/4351' 772a2a1
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge branch 'hotfix/4351' into develop 8bbb79e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  library/Zend/Validator/NotEmpty.php
@@ -90,7 +90,7 @@ public function __construct($options = null)
$detected = 0;
$found = false;
foreach ($options as $option) {
- if (in_array($option, $this->constants)) {
+ if (in_array($option, $this->constants, true)) {
$found = true;
$detected += array_search($option, $this->constants);
}
View
6 tests/ZendTest/Validator/NotEmptyTest.php
@@ -589,6 +589,12 @@ public function testEqualsMessageTemplates()
$this->assertAttributeEquals($validator->getOption('messageTemplates'),
'messageTemplates', $validator);
}
+
+ public function testTypeAutoDetectionHasNoSideEffect()
+ {
+ $validator = new NotEmpty(array('translatorEnabled' => true));
+ $this->assertEquals(493, $validator->getType());
+ }
}
class ClassTest2
Something went wrong with that request. Please try again.