diff --git a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php index 1ae8b39948..0b60eee159 100644 --- a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php @@ -51,7 +51,7 @@ class LuhnValidator extends ConstraintValidator $sum += (($i % 2) === $oddLength) ? array_sum(str_split($digit * 2)) : $digit; } - if (($sum % 10) !== 0) { + if ($sum === 0 || ($sum % 10) !== 0) { $this->context->addViolation($constraint->message); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php index 3c05778639..963710860b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php @@ -102,6 +102,8 @@ class LuhnValidatorTest extends \PHPUnit_Framework_TestCase return array( array('1234567812345678'), array('4222222222222222'), + array('0000000000000000'), + array(0), ); } }