8000 [Validator] Update NotBlankValidator "trim" option to be Unicode aware · symfony/symfony@4194fcf · GitHub
[go: up one dir, main page]

Skip to content

Commit 4194fcf

Browse files
committed
[Validator] Update NotBlankValidator "trim" option to be Unicode aware
1 parent 3c5ef08 commit 4194fcf

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Symfony/Component/Validator/Constraints/NotBlankValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function validate($value, Constraint $constraint)
2929
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\NotBlank');
3030
}
3131

32-
$normalizedValue = $constraint->trim ? trim($value) : $value;
32+
$normalizedValue = $constraint->trim && is_string($value) ? preg_replace('/[\pZ\pC]+/u', '', $value) : $value;
3333

3434
if (false === $normalizedValue || (empty($normalizedValue) && '0' != $normalizedValue)) {
3535
$this->context->buildViolation($constraint->message)

src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public function getValidValues()
4646
public function getWhitespaces()
4747
{
4848
return array(
49-
array("\x20"),
50-
array("\x09"),
51-
array("\x0A"),
52-
array("\x0D"),
53-
array("\x0B"),
49+
array("\u{0020}"),
50+
array("\u{00A0}\u{00A0}"),
51+
array("\u{1680}\u{1680}"),
52+
array("\u{200B}"),
53+
array("\u{FEFF}"),
5454
);
5555
}
5656

0 commit comments

Comments
 (0)
0