Skip to content

Commit

Permalink
Suppress getimagesize() warnings (#17944)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
adamwathan authored and taylorotwell committed Feb 16, 2017
1 parent 0b1d587 commit 6f13147
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ protected function validateDigitsBetween($attribute, $value, $parameters)
*/
protected function validateDimensions($attribute, $value, $parameters)
{
if (! $this->isValidFileInstance($value) || ! $sizeDetails = getimagesize($value->getRealPath())) {
if (! $this->isValidFileInstance($value) || ! $sizeDetails = @getimagesize($value->getRealPath())) {
return false;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,13 @@ public function testValidateImageDimensions()

$v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:ratio=1']);
$this->assertTrue($v->fails());

// This test fails without suppressing warnings on getimagesize() due to a read error.
$emptyUploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/empty.gif', '', null, null, null, true);
$trans = $this->getIlluminateArrayTranslator();

$v = new Validator($trans, ['x' => $emptyUploadedFile], ['x' => 'dimensions:min_width=1']);
$this->assertTrue($v->fails());
}

/**
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6f13147

Please sign in to comment.