File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -39,8 +39,14 @@ public function validate($value, Constraint $constraint)
39
39
40
40
$ stringValue = (string ) $ value ;
41
41
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 ;
44
50
}
45
51
46
52
if ($ invalidCharset ) {
@@ -54,6 +60,8 @@ public function validate($value, Constraint $constraint)
54
60
return ;
55
61
}
56
62
63
+ $ length = mb_strlen ($ stringValue , $ constraint ->charset );
64
+
57
65
if (null !== $ constraint ->max && $ length > $ constraint ->max ) {
58
66
$ this ->context ->buildViolation ($ constraint ->min == $ constraint ->max ? $ constraint ->exactMessage : $ constraint ->maxMessage )
59
67
->setParameter ('{{ value }} ' , $ this ->formatValue ($ stringValue ))
You can’t perform that action at this time.
0 commit comments