bug #10494 [2.3][Validator] Minor fix in IBAN validator (sprain)

This PR was merged into the 2.3 branch.

Discussion
----------

[2.3][Validator] Minor fix in IBAN validator

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10481, #10489
| License       | MIT

Added more values to unit tests of IBAN validator to make clear it doesn't accept lower case letters.

> Permitted IBAN characters are the digits 0 to 9 and the 26 upper-case Latin alphabetic characters A to Z.
http://en.wikipedia.org/wiki/International_Bank_Account_Number

Also made little adjustment to code which meant to validate lowercase letters but actually was useless.

Commits
-------

3eeb306 Fix IBAN validator
This commit is contained in:
Fabien Potencier 2014-03-19 17:10:10 +01:00
commit 65f024234d
2 changed files with 6 additions and 2 deletions

View File

@ -31,7 +31,7 @@ class IbanValidator extends ConstraintValidator
}
// An IBAN without a country code is not an IBAN.
if (0 === preg_match('/[A-Za-z]/', $value)) {
if (0 === preg_match('/[A-Z]/', $value)) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
return;
@ -50,7 +50,7 @@ class IbanValidator extends ConstraintValidator
.strval(ord($teststring{1}) - 55)
.substr($teststring, 2, 2);
$teststring = preg_replace_callback('/[A-Za-z]/', function ($letter) {
$teststring = preg_replace_callback('/[A-Z]/', function ($letter) {
return intval(ord(strtolower($letter[0])) - 87);
}, $teststring);

View File

@ -182,6 +182,10 @@ class IbanValidatorTest extends \PHPUnit_Framework_TestCase
array('foo'),
array('123'),
array('0750447346'),
//Ibans with lower case values are invalid
array('Ae260211000000230064016'),
array('ae260211000000230064016')
);
}
}