Skip to content

Commit d49f884

Browse files
Merge branch '5.0' into 5.1
* 5.0: (28 commits) [Cache] $lifetime cannot be null [Serializer] minor cleanup fix merge Run PHP 8 as 7.4.99 Remove calls to deprecated ReflectionParameter::getClass(). [VarDumper] fix PHP 8 support Add php 8 to travis. [Cache] Accessing undefined constants raises an Error in php8 [Cache] allow DBAL v3 Skip Doctrine DBAL on php 8 until we have a compatible version. [DomCrawler] Catch expected ValueError. Made method signatures compatible with their corresponding traits. [ErrorHandler] Apply php8 fixes from Debug component. [DomCrawler] Catch expected ValueError. [Validator] Catch expected ValueError. [VarDumper] ReflectionFunction::isDisabled() is deprecated. [BrowserKit] Raw body with custom Content-Type header [PropertyAccess] Parse php 8 TypeErrors correctly. [Intl] Fix call to ReflectionProperty::getValue() for static properties. [HttpKernel] Prevent calling method_exists() with non-string values. ...
2 parents d2ab255 + 988fbc1 commit d49f884

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
@@ -44,8 +44,14 @@ public function validate($value, Constraint $constraint)
4444
$stringValue = ($constraint->normalizer)($stringValue);
4545
}
4646

47-
if (!$invalidCharset = !@mb_check_encoding($stringValue, $constraint->charset)) {
48-
$length = mb_strlen($stringValue, $constraint->charset);
47+
try {
48+
$invalidCharset = !@mb_check_encoding($stringValue, $constraint->charset);
49+
} catch (\ValueError $e) {
50+
if (!str_starts_with($e->getMessage(), 'mb_check_encoding(): Argument #2 ($encoding) must be a valid encoding')) {
51+
throw $e;
52+
}
53+
54+
$invalidCharset = true;
4955
}
5056

5157
if ($invalidCharset) {
@@ -59,6 +65,8 @@ public function validate($value, Constraint $constraint)
5965
return;
6066
}
6167

68+
$length = mb_strlen($stringValue, $constraint->charset);
69+
6270
if (null !== $constraint->max && $length > $constraint->max) {
6371
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
6472
->setParameter('{{ value }}', $this->formatValue($stringValue))

0 commit comments

Comments
 (0)