From 5894291ab4c848b6125de1ea96ec3e047aeab158 Mon Sep 17 00:00:00 2001 From: NEGits <33746490+NEGits@users.noreply.github.com> Date: Mon, 30 Nov 2020 11:58:06 +0100 Subject: [PATCH 1/5] [8.x] Fix validating image/jpeg images after Symfony/Mime update Symfony/Mime v5.20 changed the returned extension for an image with image/jpeg mime type: https://github.com/symfony/mime/commit/aa1d922a7c32aedc10f6647ded250535ee3c6346 This breaks laravel image validation, as it relied on a return value of `.jpeg`. This commit changes `.jpeg` to `.jpg`, which fixes the validation. I coudn't find any tests for this part of the framework, but I'm not very familiar with the framework tests, so this might be an oversight on my part. --- 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 c07e7063e97d..302c616e4757 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1036,7 +1036,7 @@ public function validateLte($attribute, $value, $parameters) */ public function validateImage($attribute, $value) { - return $this->validateMimes($attribute, $value, ['jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']); + return $this->validateMimes($attribute, $value, ['jpg', 'png', 'gif', 'bmp', 'svg', 'webp']); } /** From 92d7870a1da085e2c09cbd34b440f65ad24b6739 Mon Sep 17 00:00:00 2001 From: NEGits <33746490+NEGits@users.noreply.github.com> Date: Mon, 30 Nov 2020 12:10:24 +0100 Subject: [PATCH 2/5] [8.x] Update ValidationValidatorTest test --- tests/Validation/ValidationValidatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 9b2a96d3591e..46d1665fc3a3 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2837,7 +2837,7 @@ public function testValidateImage() $this->assertFalse($v->passes()); $file2 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock(); - $file2->expects($this->any())->method('guessExtension')->willReturn('jpeg'); + $file2->expects($this->any())->method('guessExtension')->willReturn('jpg'); $file2->expects($this->any())->method('getClientOriginalExtension')->willReturn('jpeg'); $v = new Validator($trans, ['x' => $file2], ['x' => 'Image']); $this->assertTrue($v->passes()); From 44131b22309b49694c1092d5b329d4f10f504a58 Mon Sep 17 00:00:00 2001 From: NEGits <33746490+NEGits@users.noreply.github.com> Date: Mon, 30 Nov 2020 12:33:53 +0100 Subject: [PATCH 3/5] [8.x] Keep jpeg extension --- 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 302c616e4757..4efdefddaf6e 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -1036,7 +1036,7 @@ public function validateLte($attribute, $value, $parameters) */ public function validateImage($attribute, $value) { - return $this->validateMimes($attribute, $value, ['jpg', 'png', 'gif', 'bmp', 'svg', 'webp']); + return $this->validateMimes($attribute, $value, ['jpeg', 'jpg', 'png', 'gif', 'bmp', 'svg', 'webp']); } /** From 4e69adc6e228a69e41a95294b812f2317740c2a2 Mon Sep 17 00:00:00 2001 From: NEGits <33746490+NEGits@users.noreply.github.com> Date: Mon, 30 Nov 2020 12:35:49 +0100 Subject: [PATCH 4/5] [8.x] Restore jpeg extension for existing test, Add jpg --- tests/Validation/ValidationValidatorTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 46d1665fc3a3..3673f0c32449 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2837,7 +2837,7 @@ public function testValidateImage() $this->assertFalse($v->passes()); $file2 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock(); - $file2->expects($this->any())->method('guessExtension')->willReturn('jpg'); + $file2->expects($this->any())->method('guessExtension')->willReturn('jpeg'); $file2->expects($this->any())->method('getClientOriginalExtension')->willReturn('jpeg'); $v = new Validator($trans, ['x' => $file2], ['x' => 'Image']); $this->assertTrue($v->passes()); @@ -2871,6 +2871,12 @@ public function testValidateImage() $file7->expects($this->any())->method('getClientOriginalExtension')->willReturn('webp'); $v = new Validator($trans, ['x' => $file7], ['x' => 'Image']); $this->assertTrue($v->passes()); + + $file8 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock(); + $file8->expects($this->any())->method('guessExtension')->willReturn('jpg'); + $file8->expects($this->any())->method('getClientOriginalExtension')->willReturn('jpg'); + $v = new Validator($trans, ['x' => $file8], ['x' => 'Image']); + $this->assertTrue($v->passes()); } public function testValidateImageDoesNotAllowPhpExtensionsOnImageMime() From aa3a8c7545d52c35448d026c44d4cf9964dc27a3 Mon Sep 17 00:00:00 2001 From: NEGits <33746490+NEGits@users.noreply.github.com> Date: Mon, 30 Nov 2020 12:41:41 +0100 Subject: [PATCH 5/5] [8.x] Style fix --- tests/Validation/ValidationValidatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 3673f0c32449..c68139cf8d1d 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2871,7 +2871,7 @@ public function testValidateImage() $file7->expects($this->any())->method('getClientOriginalExtension')->willReturn('webp'); $v = new Validator($trans, ['x' => $file7], ['x' => 'Image']); $this->assertTrue($v->passes()); - + $file8 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock(); $file8->expects($this->any())->method('guessExtension')->willReturn('jpg'); $file8->expects($this->any())->method('getClientOriginalExtension')->willReturn('jpg');