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

Commit 5f28b5a

Browse files
committed
Hash provided in File\Hash validator must be a string
We were checking it when we providing one hash, but there was no check for array: ``` $options = [ 'hash1', 'hash2', // ... 'algorithm' => '...', ]; ```
1 parent 089307b commit 5f28b5a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/File/Hash.php

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

116116
foreach ($options as $value) {
117+
if (! is_string($value)) {
118+
throw new Exception\InvalidArgumentException(sprintf(
119+
'Hash must be a string, %s received',
120+
is_object($value) ? get_class($value) : gettype($value)
121+
));
122+
}
117123
$this->options['hash'][$value] = $algorithm;
118124
}
119125

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)