Skip to content

Commit

Permalink
[6.x] Fix validating image/jpeg images after Symfony/Mime update (lar…
Browse files Browse the repository at this point in the history
…avel#35419)

* [6.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: symfony/mime@aa1d922. This commit adds `.jpg`, which fixes the validation.

* [6.x] Add test for image validation with jpg extension

(cherry picked from commit fff077c)
  • Loading branch information
Grldk authored and txp committed Feb 18, 2021
1 parent 78eb4da commit c39d432
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Expand Up @@ -1011,7 +1011,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', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Expand Up @@ -2514,6 +2514,12 @@ public function testValidateImage()
$file7->expects($this->any())->method('getClientOriginalExtension')->will($this->returnValue('webp'));
$v = new Validator($trans, ['x' => $file7], ['x' => 'Image']);
$this->assertTrue($v->passes());

$file2 = $this->getMockBuilder(UploadedFile::class)->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
$file2->expects($this->any())->method('guessExtension')->willReturn('jpg');
$file2->expects($this->any())->method('getClientOriginalExtension')->willReturn('jpg');
$v = new Validator($trans, ['x' => $file2], ['x' => 'Image']);
$this->assertTrue($v->passes());
}

public function testValidateImageDoesNotAllowPhpExtensionsOnImageMime()
Expand Down

0 comments on commit c39d432

Please sign in to comment.