Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 11436cb

Browse filesBrowse files
committed
[Validator] Catch expected ValueError.
1 parent 52abcbe commit 11436cb
Copy full SHA for 11436cb

File tree

3 files changed

+13
-3
lines changed
Filter options

3 files changed

+13
-3
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"symfony/polyfill-intl-icu": "~1.0",
3232
"symfony/polyfill-mbstring": "~1.0",
3333
"symfony/polyfill-php56": "~1.0",
34-
"symfony/polyfill-php70": "~1.6"
34+
"symfony/polyfill-php70": "~1.6",
35+
"symfony/polyfill-php80": "~1.17"
3536
},
3637
"replace": {
3738
"symfony/asset": "self.version",

‎src/Symfony/Component/Validator/Constraints/LengthValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/LengthValidator.php
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ public function validate($value, Constraint $constraint)
3939

4040
$stringValue = (string) $value;
4141

42-
if (!$invalidCharset = !@mb_check_encoding($stringValue, $constraint->charset)) {
43-
$length = mb_strlen($stringValue, $constraint->charset);
42+
try {
43+
$invalidCharset = !@mb_check_encoding($stringValue, $constraint->charset);
44+
} catch (\ValueError $e) {
45+
if (!str_starts_with($e->getMessage(), 'mb_check_encoding(): Argument #2 ($encoding) must be a valid encoding')) {
46+
throw $e;
47+
}
48+
49+
$invalidCharset = true;
4450
}
4551

4652
if ($invalidCharset) {
@@ -54,6 +60,8 @@ public function validate($value, Constraint $constraint)
5460
return;
5561
}
5662

63+
$length = mb_strlen($stringValue, $constraint->charset);
64+
5765
if (null !== $constraint->max && $length > $constraint->max) {
5866
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
5967
->setParameter('{{ value }}', $this->formatValue($stringValue))

‎src/Symfony/Component/Validator/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"php": "^5.5.9|>=7.0.8",
2020
"symfony/polyfill-ctype": "~1.8",
2121
"symfony/polyfill-mbstring": "~1.0",
22+
"symfony/polyfill-php80": "~1.17",
2223
"symfony/translation": "~2.8|~3.0|~4.0"
2324
},
2425
"require-dev": {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.