Skip to content

Commit 9ed27d0

Browse files
committed
feature symfony#57380 [Validator] fix IBAN validator fails if IBAN contains non-breaking space (antten)
This PR was submitted for the 5.4 branch but it was squashed and merged into the 7.2 branch instead. Discussion ---------- [Validator] fix IBAN validator fails if IBAN contains non-breaking space | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#57364 | License | MIT Hello, It's my first contribution to Symfony and I am really happy to be able to participate in the project. After analyzing the class \Symfony\Component\Validator\Constraints\IbanValidator, I think the solution proposed in the issue is the right one. Commits ------- 6f6c4b7 [Validator] fix IBAN validator fails if IBAN contains non-breaking space
2 parents f58b37a + 6f6c4b7 commit 9ed27d0

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

+2-2
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

+2
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)