Skip to content

Commit

Permalink
[5.6] Ignore svg's in validateDimensions() (#21390)
Browse files Browse the repository at this point in the history
* Ignore svg's in validateDimensions()

SVG dimensions are pretty irrelevant, so they should simply pass this test.

* Change svg test to check for mime instead of ext in validateDimensions()
  • Loading branch information
tobz-nz authored and taylorotwell committed Sep 26, 2017
1 parent 7619e4f commit a3f5b19
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ public function validateDigitsBetween($attribute, $value, $parameters)
*/
public function validateDimensions($attribute, $value, $parameters)
{
if ($this->isValidFileInstance($value) && $value->getClientMimeType() == 'image/svg+xml') {
return true;
}

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 @@ -2102,6 +2102,13 @@ public function testValidateImageDimensions()
// Ensure validation doesn't erroneously fail when ratio has no fractional part
$v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:ratio=2/3']);
$this->assertTrue($v->passes());

// Ensure svg images always pass as size is irreleveant
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image.svg', '', 'image/svg+xml', null, null, true);
$trans = $this->getIlluminateArrayTranslator();

$v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:max_width=1,max_height=1']);
$this->assertTrue($v->passes());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Validation/fixtures/image.svg
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 a3f5b19

Please sign in to comment.