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

Commit

Permalink
Merge branch 'hotfix/231'
Browse files Browse the repository at this point in the history
Close #231
  • Loading branch information
michalbundyra committed Oct 12, 2019
2 parents 1eab945 + 443e523 commit c5c14ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ All notable changes to this project will be documented in this file, in reverse
curly braces in array and string offset access to square brackets
in order to prevent issues under the upcoming PHP 7.4 release.

- [#231](https://github.com/zendframework/zend-validator/pull/231) fixes validation of input hashes in `Zend\Validator\File\Hash` validator when provided as array.
Only string hashes are allowed. If different type is provided `Zend\Validator\Exception\InvalidArgumentException` is thrown.

## 2.12.0 - 2019-01-30

### Added
Expand Down
6 changes: 6 additions & 0 deletions src/File/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public function addHash($options)
}

foreach ($options as $value) {
if (! is_string($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Hash must be a string, %s received',
is_object($value) ? get_class($value) : gettype($value)
));
}
$this->options['hash'][$value] = $algorithm;
}

Expand Down
14 changes: 14 additions & 0 deletions test/File/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,18 @@ public function testConstructorCanAcceptAllOptionsAsDiscreteArguments()
$options = $r->getValue($validator);
$this->assertSame($algorithm, $options['algorithm']);
}

/**
* @dataProvider invalidHashTypes
*
* @param mixed $hash
*/
public function testInvalidHashProvidedInArrayFormat($hash)
{
$validator = new File\Hash('12345');

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Hash must be a string');
$validator->addHash([$hash]);
}
}

0 comments on commit c5c14ec

Please sign in to comment.