Skip to content

[Validator] fix IBAN validator fails if IBAN contains non-breaking space #57380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/IbanValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ public function validate(mixed $value, Constraint $constraint): void

$value = (string) $value;

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

// The IBAN must contain only digits and characters...
if (!ctype_alnum($canonicalized)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public static function getValidIbans()
['FO97 5432 0388 8999 44'], // Faroe Islands
['FI21 1234 5600 0007 85'], // Finland
['FR14 2004 1010 0505 0001 3M02 606'], // France
["FR14\xc2\xa02004\xc2\xa01010\xc2\xa00505\xc2\xa00001\xc2\xa03M02\xc2\xa0606"], // France with non-breaking spaces
["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
['GE29 NB00 0000 0101 9049 17'], // Georgia
['DE89 3704 0044 0532 0130 00'], // Germany
['GI75 NWBK 0000 0000 7099 453'], // Gibraltar
Expand Down
Loading