Skip to content

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

@fmarchalemisys

Description

@fmarchalemisys

Symfony version(s) affected

6.4.8

Description

IBAN validator fails if IBAN is copy/pasted from a source that formatted the IBAN with non-breaking space as separator. This is common on web banking apps and pdf documents issued by banks.

For instance, BE00 0000 0000 0000, with hex string 42453030c2a030303030c2a030303030c2a030303030, fails to validate (assuming the IBAN is otherwise valid which is not the case with this sample IBAN 🙂 ).

The Iban validator only strips plain ASCII spaces.

How to reproduce

Generate a random but correct looking iban such as "FR841450800040\xc2\xa08782897835E04" with at least one non-breaking space (\xc2\xa0) somewhere in the string.

Validate that string with the Iban validator. Notice the IBAN is reported as invalid.

Possible Solution

Add non-breaking space to the stripped characters in

$canonicalized = str_replace(' ', '', strtoupper($value));

This change fixed the issue for me:

$canonicalized = str_replace([' ', "\xc2\xa0"], [''], strtoupper($value));

It might not be the most elegant solution though 🙂

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions