Skip to content

Commit 62f66d9

Browse files
Merge branch '5.4' into 6.0
* 5.4: (22 commits) Fix composer on appveyor fix bootstrap_3_layout ChoiceType's expanded label_html [PropertyAccess] Fix typo in PropertyAccessor::readProperty() DocBlock [PropertyInfo] PhpStanExtractor namespace missmatch issue [VarExporter] Fix exporting objects with readonly properties [ExpressionLanguage] Fix matches when the regexp is not valid [Messenger] Add mysql indexes back and work around deadlocks using soft-delete Add BC layer to handle old objects already present in cache [RateLimiter] Always store SlidingWindows with an expiration set [Validator] Fix File constraint invalid max size exception message [Console] Fix exit status on uncaught exception with negative code [Validator] fix #43345 @Assert\DivisibleBy [HttpClient] fix 303 after PUT and sending chunked requests [HttpClient] always send Content-Type when a body is passed [HttpClient] always send Content-Length when a body is passed [HttpClient] fix sending Content-Length/Type for POST Fix merge [HttpClient] fix sending PUT requests with curl Fix locales format in CrowdinProvider Fix intersect in TranslatorBag ...
2 parents 4d5eedd + f6402ff commit 62f66d9

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

Constraints/DivisibleByValidator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ protected function compareValues(mixed $value1, mixed $value2): bool
4242
if (!$remainder = fmod($value1, $value2)) {
4343
return true;
4444
}
45+
if (\is_float($value2) && \INF !== $value2) {
46+
$quotient = $value1 / $value2;
47+
$rounded = round($quotient);
48+
49+
return sprintf('%.12e', $quotient) === sprintf('%.12e', $rounded);
50+
}
4551

4652
return sprintf('%.12e', $value2) === sprintf('%.12e', $remainder);
4753
}

Constraints/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private function normalizeBinaryFormat(int|string $maxSize)
152152
$this->maxSize = $matches[1] * $factors[$unit = strtolower($matches[2])];
153153
$this->binaryFormat = $this->binaryFormat ?? (2 === \strlen($unit));
154154
} else {
155-
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size.', $this->maxSize));
155+
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size.', $maxSize));
156156
}
157157
}
158158
}

Tests/Constraints/DivisibleByValidatorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ public function provideValidComparisons(): array
4646
[0, 3.1415],
4747
[42, 42],
4848
[42, 21],
49+
[10.12, 0.01],
50+
[10.12, 0.001],
51+
[1.133, 0.001],
52+
[1.1331, 0.0001],
53+
[1.13331, 0.00001],
54+
[1.13331, 0.000001],
55+
[1, 0.1],
56+
[1, 0.01],
57+
[1, 0.001],
58+
[1, 0.0001],
59+
[1, 0.00001],
60+
[1, 0.000001],
4961
[3.25, 0.25],
5062
['100', '10'],
5163
[4.1, 0.1],
@@ -74,6 +86,7 @@ public function provideInvalidComparisons(): array
7486
[10, '10', 0, '0', 'int'],
7587
[42, '42', \INF, 'INF', 'float'],
7688
[4.15, '4.15', 0.1, '0.1', 'float'],
89+
[10.123, '10.123', 0.01, '0.01', 'float'],
7790
['22', '"22"', '10', '"10"', 'string'],
7891
];
7992
}

Tests/Constraints/FileValidatorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,5 +517,14 @@ public function uploadedFileErrorProvider()
517517
return $tests;
518518
}
519519

520+
public function testNegativeMaxSize()
521+
{
522+
$this->expectException(ConstraintDefinitionException::class);
523+
$this->expectExceptionMessage('"-1" is not a valid maximum size.');
524+
525+
$file = new File();
526+
$file->maxSize = -1;
527+
}
528+
520529
abstract protected function getFile($filename);
521530
}

0 commit comments

Comments
 (0)