8000 merged branch ricardclau/improve-luhn-validator (PR #6591) · symfony/symfony@d8be36c · GitHub
[go: up one dir, main page]

Skip to content

Commit d8be36c

Browse files
committed
merged branch ricardclau/improve-luhn-validator (PR #6591)
This PR was merged into the master branch. Commits ------- b1f190f covers edge case for Luhn Discussion ---------- [Validator] Covering edge case for Luhn when checksum is exactly 0 Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: Todo: License of the code: MIT Documentation PR: Actually not a big deal, but a Credit Card with all 0s passed validation. Now this is covered.
2 parents 64bf80c + b1f190f commit d8be36c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Symfony/Component/Validator/Constraints/LuhnValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function validate($value, Constraint $constraint)
5151
$sum += (($i % 2) === $oddLength) ? array_sum(str_split($digit * 2)) : $digit;
5252
}
5353

54-
if (($sum % 10) !== 0) {
54+
if ($sum === 0 || ($sum % 10) !== 0) {
5555
$this->context->addViolation($constraint->message);
5656
}
5757
}

src/Symfony/Component/Validator/Tests/Constraints/LuhnValidatorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public function getInvalidNumbers()
102102
return array(
103103
array('1234567812345678'),
104104
array('4222222222222222'),
105+
array('0000000000000000'),
106+
array(0),
105107
);
106108
}
107109
}

0 commit comments

Comments
 (0)
0