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 3c5ef08

Browse filesBrowse files
committed
[Validator] Update LengthValidator trimming options to be Unicode aware
1 parent 45c9cb1 commit 3c5ef08
Copy full SHA for 3c5ef08

File tree

Expand file treeCollapse file tree

2 files changed

+14
-18
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-18
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/LengthValidator.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public function validate($value, Constraint $constraint)
4040
$stringValue = (string) $value;
4141
$normalizedString = $stringValue;
4242

43-
$normalizedString = $constraint->ltrim ? ltrim($normalizedString) : $normalizedString;
44-
$normalizedString = $constraint->rtrim ? rtrim($normalizedString) : $normalizedString;
43+
$normalizedString = $constraint->ltrim ? preg_replace('/^[\pZ\pC]+/u', '', $normalizedString) : $normalizedString;
44+
$normalizedString = $constraint->rtrim ? preg_replace('/[\pZ\pC]+$/u', '', $normalizedString) : $normalizedString;
4545

46-
$normalizedString = $constraint->mergeConsecutiveWhitespaces ? preg_replace('/\s+/', ' ', $normalizedString) : $normalizedString;
46+
$normalizedString = $constraint->mergeConsecutiveWhitespaces ? preg_replace('/[\pZ\pC]+/u', ' ', $normalizedString) : $normalizedString;
4747

4848
if (!$invalidCharset = !@mb_check_encoding($stringValue, $constraint->charset)) {
4949
$length = mb_strlen($normalizedString, $constraint->charset);

‎src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php
+11-15Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,29 @@ public function getOneCharset()
9595
public function getThreeCharactersWithLeadingWhitespaces()
9696
{
9797
return array(
98-
array("\x20123"),
99-
array("\x09üüü"),
100-
array("\x0Aééé"),
101-
array("\x0D123"),
102-
array("\x0Bééé"),
98+
array("\u{0020}ccc"),
99+
array("\u{00A0}c\u{00A0}c"),
100+
array("\u{1680}cc\u{1680}"),
101+
array("\u{200B}\u{200B}ccc"),
103102
);
104103
}
105104

106105
public function getThreeCharactersWithTrailingWhitespaces()
107106
{
108107
return array(
109-
array("123\x20"),
110-
array("üüü\x09"),
111-
array("ééé\x0A"),
112-
array("123\x0D"),
113-
array("ééé\x0B"),
108+
array("ccc\u{0020}"),
109+
array("c\u{00A0}c\u{00A0}"),
110+
array("\u{1680}cc\u{1680}"),
111+
array("ccc\u{200B}\u{200B}"),
114112
);
115113
}
116114

117115
public function getThreeCharactersWithConsecutiveWhitespaces()
118116
{
119117
return array(
120-
array("123\x20\x20"),
121-
array("\x09\x09üüü"),
122-
array("é\x0A\x0Aéé"),
123-
array("123\x0D\x0D"),
124-
array("éé\x0B\x0Bé"),
118+
array("ccc\u{0020}\u{0020}"),
119+
array("\u{00A0}\u{00A0}ccc"),
120+
array("c\u{1680}\u{1680}c\u{1680}"),
125121
);
126122
}
127123

0 commit comments

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