Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ protected function failsRatioCheck($parameters, $width, $height)
[1, 1], array_filter(sscanf($parameters['ratio'], '%f/%d'))
);

return abs($numerator / $denominator - $width / $height) > 0.000001;
$precision = 1 / max($width, $height);

return abs($numerator / $denominator - $width / $height) > $precision;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/Validation/ValidationDimensionsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
$rule = Rule::dimensions()->maxWidth(1000)->maxHeight(500)->ratio(3 / 2);

$this->assertEquals('dimensions:max_width=1000,max_height=500,ratio=1.5', (string) $rule);

$rule = new Dimensions(['ratio' => '2/3']);

$this->assertEquals('dimensions:ratio=2/3', (string) $rule);
}
}
11 changes: 11 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,9 @@ public function testValidateImage()
$this->assertTrue($v->passes());
}

/**
* @group dimension
*/
public function testValidateImageDimensions()
{
// Knowing that demo image.png has width = 3 and height = 2
Expand Down Expand Up @@ -2037,6 +2040,14 @@ public function testValidateImageDimensions()

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

// Knowing that demo image3.png has width = 7 and height = 10
$uploadedFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(__DIR__.'/fixtures/image3.png', '', null, null, null, true);
$trans = $this->getIlluminateArrayTranslator();

// 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());
}

/**
Expand Down
Binary file added tests/Validation/fixtures/image3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.