From e7949e71bfac0cb3aff7363dae6bebc9d28aeb6b Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Sun, 24 Sep 2017 19:50:36 +1300 Subject: [PATCH 1/2] Ignore svg's in validateDimensions() SVG dimensions are pretty irrelevant, so they should simply pass this test. --- src/Illuminate/Validation/Concerns/ValidatesAttributes.php | 4 ++++ tests/Validation/ValidationValidatorTest.php | 7 +++++++ tests/Validation/fixtures/image.svg | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 tests/Validation/fixtures/image.svg diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index e4bcd813425f..fad3f556e030 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->getExtension() == 'svg') { + 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 @@ + + From f876c99fce8d96e2737d46e6d133bb22ba7fd571 Mon Sep 17 00:00:00 2001 From: Toby Evans Date: Tue, 26 Sep 2017 09:36:10 +1300 Subject: [PATCH 2/2] Change svg test to check for mime instead of ext in validateDimensions() --- src/Illuminate/Validation/Concerns/ValidatesAttributes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index fad3f556e030..af5e2f2e18fb 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -447,7 +447,7 @@ public function validateDigitsBetween($attribute, $value, $parameters) */ public function validateDimensions($attribute, $value, $parameters) { - if ($this->isValidFileInstance($value) && $value->getExtension() == 'svg') { + if ($this->isValidFileInstance($value) && $value->getClientMimeType() == 'image/svg+xml') { return true; }