Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Fix ratio validation for high ratio images #51296

Merged
merged 6 commits into from
May 5, 2024
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
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ protected function failsRatioCheck($parameters, $width, $height)
[1, 1], array_filter(sscanf($parameters['ratio'], '%f/%d'))
);

$precision = 1 / (max($width, $height) + 1);
$precision = 1 / (max(($width + $height) / 2, $height) + 1);

return abs($numerator / $denominator - $width / $height) > $precision;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4922,6 +4922,13 @@ public function testValidateImageDimensions()
// Ensure validation doesn't erroneously fail when ratio doesn't matches
$v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:ratio=1']);
$this->assertFalse($v->passes());

// Knowing that demo image5.png has width = 1366 and height = 768
$uploadedFile = new UploadedFile(__DIR__.'/fixtures/image5.png', '', null, null, true);
$trans = $this->getIlluminateArrayTranslator();

$v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:ratio=16/9']);
$this->assertTrue($v->passes());
}

public function testValidateMimetypes()
Expand Down
Binary file added tests/Validation/fixtures/image5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.