8000 covers edge case for Luhn · symfony/symfony@b1f190f · GitHub
[go: up one dir, main page]

Skip to content

Commit b1f190f

Browse files
committed
covers edge case for Luhn
1 parent 64bf80c commit b1f190f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

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

< BAC4 span class="prc-TooltipV2-Tooltip-cYMVY" data-direction="s" role="tooltip" aria-hidden="true" id=":Rhmtlab:">Expand all lines: 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