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

Commit

Permalink
Merge branch 'hotfix/4567'
Browse files Browse the repository at this point in the history
Close #4567
  • Loading branch information
weierophinney committed Jun 28, 2013
2 parents 6be1059 + 5f21c56 commit eb6f0ef
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions library/Zend/InputFilter/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ protected function validateInputs(array $inputs)
&& '' === $this->data[$name]
&& $input instanceof InputInterface
&& !$input->isRequired()
&& $input->allowEmpty()
) {
$this->validInputs[$name] = $input;
continue;
Expand Down
4 changes: 2 additions & 2 deletions library/Zend/InputFilter/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ public function createInput($inputSpecification)
break;
case 'required':
$input->setRequired($value);
if (!isset($inputSpecification['allow_empty'])) {
$input->setAllowEmpty(!$value);
if (isset($inputSpecification['allow_empty'])) {
$input->setAllowEmpty($inputSpecification['allow_empty']);
}
break;
case 'allow_empty':
Expand Down
1 change: 1 addition & 0 deletions library/Zend/InputFilter/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function setName($name)
public function setRequired($required)
{
$this->required = (bool) $required;
$this->setAllowEmpty(!$required);
return $this;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/ZendTest/InputFilter/BaseInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,22 @@ public function testValidationMarksInputInvalidWhenRequiredAndAllowEmptyFlagIsFa
$this->assertFalse($filter->isValid());
}

public function testValidationMarksInputInvalidWhenNotRequiredAndAllowEmptyFlagIsFalse()
{
$filter = new InputFilter();

$foo = new Input();
$foo->setRequired(false);
$foo->setAllowEmpty(false);

$filter->add($foo, 'foo');

$data = array('foo' => '');
$filter->setData($data);

$this->assertFalse($filter->isValid());
}

public static function contextDataProvider()
{
return array(
Expand Down

0 comments on commit eb6f0ef

Please sign in to comment.