Skip to content

Commit

Permalink
fix dimensions validation when file not provided (#14025)
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-dev authored and taylorotwell committed Jun 21, 2016
1 parent 002de78 commit a0dbc55
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ protected function validateImage($attribute, $value)
*/
protected function validateDimensions($attribute, $value, $parameters)
{
if (! $sizeDetails = getimagesize($value->getRealPath())) {
if (! $this->isAValidFileInstance($value) || ! $sizeDetails = getimagesize($value->getRealPath())) {
return false;
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1665,9 +1665,12 @@ public function testValidateImage()
public function testValidateImageDimensions()
{
// Knowing that demo image.gif has width = 3 and height = 2
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image.gif', '');
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image.gif', '', null, null, null, true);
$trans = $this->getRealTranslator();

$v = new Validator($trans, ['x' => 'file'], ['x' => 'dimensions']);
$this->assertTrue($v->fails());

$v = new Validator($trans, [], ['x' => 'dimensions:min_width=1']);
$v->setFiles(['x' => $uploadedFile]);
$this->assertTrue($v->passes());
Expand Down

0 comments on commit a0dbc55

Please sign in to comment.