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

Commit c5c14ec

Browse files
committed
Merge branch 'hotfix/231'
Close #231
2 parents 1eab945 + 443e523 commit c5c14ec

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ All notable changes to this project will be documented in this file, in reverse
2626
curly braces in array and string offset access to square brackets
2727
in order to prevent issues under the upcoming PHP 7.4 release.
2828

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

3134
### Added

src/File/Hash.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ public function addHash($options)
117117
}
118118

119119
foreach ($options as $value) {
120+
if (! is_string($value)) {
121+
throw new Exception\InvalidArgumentException(sprintf(
122+
'Hash must be a string, %s received',
123+
is_object($value) ? get_class($value) : gettype($value)
124+
));
125+
}
120126
$this->options['hash'][$value] = $algorithm;
121127
}
122128

test/File/HashTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,18 @@ public function testConstructorCanAcceptAllOptionsAsDiscreteArguments()
239239
$options = $r->getValue($validator);
240240
$this->assertSame($algorithm, $options['algorithm']);
241241
}
242+
243+
/**
244+
* @dataProvider invalidHashTypes
245+
*
246+
* @param mixed $hash
247+
*/
248+
public function testInvalidHashProvidedInArrayFormat($hash)
249+
{
250+
$validator = new File\Hash('12345');
251+
252+
$this->expectException(InvalidArgumentException::class);
253+
$this->expectExceptionMessage('Hash must be a string');
254+
$validator->addHash([$hash]);
255+
}
242256
}

0 commit comments

Comments
 (0)