Skip to content

Commit 425e8b9

Browse files
Merge branch '3.4' into 4.4
* 3.4: Skip Doctrine DBAL on php 8 until we have a compatible version. [DomCrawler] Catch expected ValueError. [Validator] Catch expected ValueError. [VarDumper] ReflectionFunction::isDisabled() is deprecated. [PropertyAccess] Parse php 8 TypeErrors correctly. [Intl] Fix call to ReflectionProperty::getValue() for static properties. [HttpKernel] Prevent calling method_exists() with non-string values. [Debug] php 8 does not pass $context to error handlers. [Config] Removed implicit cast of ReflectionProperty to string. [Debug] Undefined variables raise a warning in php 8. [Debug] Skip test that would trigger a fatal error on php 8. Address deprecation of ReflectionType::getClass(). Properties $originalName and $mimeType are never null in UploadedFile
2 parents 01e51e9 + 51bed7f commit 425e8b9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Constraints/LengthValidator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ public function validate($value, Constraint $constraint)
4848
$stringValue = ($constraint->normalizer)($stringValue);
4949
}
5050

51-
if (!$invalidCharset = !@mb_check_encoding($stringValue, $constraint->charset)) {
52-
$length = mb_strlen($stringValue, $constraint->charset);
51+
try {
52+
$invalidCharset = !@mb_check_encoding($stringValue, $constraint->charset);
53+
} catch (\ValueError $e) {
54+
if (!str_starts_with($e->getMessage(), 'mb_check_encoding(): Argument #2 ($encoding) must be a valid encoding')) {
55+
throw $e;
56+
}
57+
58+
$invalidCharset = true;
5359
}
5460

5561
if ($invalidCharset) {
@@ -63,6 +69,8 @@ public function validate($value, Constraint $constraint)
6369
return;
6470
}
6571

72+
$length = mb_strlen($stringValue, $constraint->charset);
73+
6674
if (null !== $constraint->max && $length > $constraint->max) {
6775
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
6876
->setParameter('{{ value }}', $this->formatValue($stringValue))

0 commit comments

Comments
 (0)