Skip to content

Commit

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

* [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
  • Loading branch information
Grldk committed Nov 30, 2020
1 parent a93d6a5 commit fff077c
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 @@ -1054,7 +1054,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 @@ -2703,6 +2703,12 @@ public function testValidateImage()
$file7->expects($this->any())->method('getClientOriginalExtension')->willReturn('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 fff077c

Please sign in to comment.