Skip to content

Commit 6f13147

Browse files
adamwathantaylorotwell
authored andcommitted
Suppress getimagesize() warnings (#17944)
* Suppress getimagesize() warnings `getimagesize` will fail with a notice on files smaller than 12 bytes. This ends up becoming an ErrorException which is pretty annoying. Suppressing the warning is enough to still end up with a `false` result which will fail the validation gracefully instead of grueing up your stew. * Add test to prove need for warning suppression
1 parent 0b1d587 commit 6f13147

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ protected function validateDigitsBetween($attribute, $value, $parameters)
424424
*/
425425
protected function validateDimensions($attribute, $value, $parameters)
426426
{
427-
if (! $this->isValidFileInstance($value) || ! $sizeDetails = getimagesize($value->getRealPath())) {
427+
if (! $this->isValidFileInstance($value) || ! $sizeDetails = @getimagesize($value->getRealPath())) {
428428
return false;
429429
}
430430

tests/Validation/ValidationValidatorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,13 @@ public function testValidateImageDimensions()
19231923

19241924
$v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:ratio=1']);
19251925
$this->assertTrue($v->fails());
1926+
1927+
// This test fails without suppressing warnings on getimagesize() due to a read error.
1928+
$emptyUploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/empty.gif', '', null, null, null, true);
1929+
$trans = $this->getIlluminateArrayTranslator();
1930+
1931+
$v = new Validator($trans, ['x' => $emptyUploadedFile], ['x' => 'dimensions:min_width=1']);
1932+
$this->assertTrue($v->fails());
19261933
}
19271934

19281935
/**

tests/Validation/fixtures/empty.gif

Loading

0 commit comments

Comments
 (0)