Skip to content

Commit

Permalink
feature symfony#57380 [Validator] fix IBAN validator fails if IBAN co…
Browse files Browse the repository at this point in the history
…ntains 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
  • Loading branch information
fabpot committed Jun 17, 2024
2 parents f58b37a + 6f6c4b7 commit 9ed27d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
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

0 comments on commit 9ed27d0

Please sign in to comment.