Skip to content

Commit 6f6c4b7

Browse files
anttenfabpot
authored andcommitted
[Validator] fix IBAN validator fails if IBAN contains non-breaking space
1 parent f58b37a commit 6f6c4b7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ public function validate(mixed $value, Constraint $constraint): void
179179

180180
$value = (string) $value;
181181

182-
// Remove spaces and convert to uppercase
183-
$canonicalized = str_replace(' ', '', strtoupper($value));
182+
// Remove spaces (regular, non-breaking, and narrow non-breaking) and convert to uppercase
183+
$canonicalized = str_replace([' ', "\xc2\xa0", "\xe2\x80\xaf"], '', strtoupper($value));
184184

185185
// The IBAN must contain only digits and characters...
186186
if (!ctype_alnum($canonicalized)) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public static function getValidIbans()
7777
['FO97 5432 0388 8999 44'], // Faroe Islands
7878
['FI21 1234 5600 0007 85'], // Finland
7979
['FR14 2004 1010 0505 0001 3M02 606'], // France
80+
["FR14\xc2\xa02004\xc2\xa01010\xc2\xa00505\xc2\xa00001\xc2\xa03M02\xc2\xa0606"], // France with non-breaking spaces
81+
["FR14\xe2\x80\xaf2004\xe2\x80\xaf1010\xe2\x80\xaf0505\xe2\x80\xaf0001\xe2\x80\xaf3M02\xe2\x80\xaf606"], // France with narrow non-breaking spaces
8082
['GE29 NB00 0000 0101 9049 17'], // Georgia
8183
['DE89 3704 0044 0532 0130 00'], // Germany
8284
['GI75 NWBK 0000 0000 7099 453'], // Gibraltar

0 commit comments

Comments
 (0)