diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index e4bcd813425f..af5e2f2e18fb 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -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; } diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 49469bd5498c..8738253d0467 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -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()); } /** diff --git a/tests/Validation/fixtures/image.svg b/tests/Validation/fixtures/image.svg new file mode 100644 index 000000000000..9a55b678ffb5 --- /dev/null +++ b/tests/Validation/fixtures/image.svg @@ -0,0 +1,2 @@ + +