Skip to content

Commit f6f8f54

Browse files
Windows and Intl fixes
1 parent b760bdc commit f6f8f54

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

Constraints/LengthValidator.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,25 @@ public function validate($value, Constraint $constraint)
4040
$charset = 'UTF-8';
4141
}
4242

43-
if (function_exists('iconv_strlen')) {
44-
$length = @iconv_strlen($stringValue, $constraint->charset);
45-
$invalidCharset = false === $length;
43+
if ('UTF-8' === $charset) {
44+
if (!preg_match('//u', $stringValue)) {
45+
$invalidCharset = true;
46+
} elseif (function_exists('utf8_decode')) {
47+
$length = strlen(utf8_decode($stringValue));
48+
} else {
49+
preg_replace('/./u', '', $stringValue, -1, $length);
50+
}
4651
} elseif (function_exists('mb_strlen')) {
47-
if (mb_check_encoding($stringValue, $constraint->charset)) {
52+
if (@mb_check_encoding($stringValue, $constraint->charset)) {
4853
$length = mb_strlen($stringValue, $constraint->charset);
4954
} else {
5055
$invalidCharset = true;
5156
}
52-
} elseif ('UTF-8' !== $charset) {
53-
$length = strlen($stringValue);
54-
} elseif (!preg_match('//u', $stringValue)) {
55-
$invalidCharset = true;
56-
} elseif (function_exists('utf8_decode')) {
57-
$length = strlen(utf8_decode($stringValue));
57+
} elseif (function_exists('iconv_strlen')) {
58+
$length = @iconv_strlen($stringValue, $constraint->charset);
59+
$invalidCharset = false === $length;
5860
} else {
59-
preg_replace('/./u', '', $stringValue, -1, $length);
61+
$length = strlen($stringValue);
6062
}
6163

6264
if ($invalidCharset) {

Tests/Constraints/ImageValidatorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Symfony\Component\Validator\Constraints\Image;
1515
use Symfony\Component\Validator\Constraints\ImageValidator;
1616

17+
/**
18+
* @requires extension fileinfo
19+
*/
1720
class ImageValidatorTest extends AbstractConstraintValidatorTest
1821
{
1922
protected $context;

0 commit comments

Comments
 (0)