From 6f6c4b7abf577296a1b25c4537702dc8747ef5b3 Mon Sep 17 00:00:00 2001 From: Anthony Tenneriello Date: Wed, 12 Jun 2024 16:09:23 +0200 Subject: [PATCH] [Validator] fix IBAN validator fails if IBAN contains non-breaking space --- src/Symfony/Component/Validator/Constraints/IbanValidator.php | 4 ++-- .../Validator/Tests/Constraints/IbanValidatorTest.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/IbanValidator.php b/src/Symfony/Component/Validator/Constraints/IbanValidator.php index 3ed971cb47de6..b7deeca155b7a 100644 --- a/src/Symfony/Component/Validator/Constraints/IbanValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IbanValidator.php @@ -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)) { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php index af3cf98acba01..834eb3f5dc191 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php @@ -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