Skip to content

Commit 10fcc2b

Browse files
committed
fix: reject non-digit characters in valid_cc_number()
Use ctype_digit() instead of is_numeric() so values such as decimal points, which is_numeric() accepts, can no longer reach the Luhn check. Previously a string like '5351367.37861108' passed validation and the Luhn indexer triggered an 'Undefined array key' warning on non-digit characters.
1 parent c21d575 commit 10fcc2b

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎system/Validation/CreditCardRules.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function valid_cc_number(?string $ccNumber, string $type): bool
200200
$ccNumber = str_replace([' ', '-'], '', $ccNumber);
201201

202202
// Non-numeric values cannot be a number...duh
203-
if (! is_numeric($ccNumber)) {
203+
if (! ctype_digit($ccNumber)) {
204204
return false;
205205
}
206206

‎tests/system/Validation/StrictRules/CreditCardRulesTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ public static function provideValidCCNumber(): iterable
100100
'abcd efgh ijkl mnop',
101101
false,
102102
],
103+
'decimal_point_visa' => [
104+
'visa',
105+
'41.1111111111111',
106+
false,
107+
],
108+
'decimal_point_mastercard' => [
109+
'mastercard',
110+
'5351367.37861108',
111+
false,
112+
],
103113
'bad_length' => [
104114
'amex',
105115
'3782 8224 6310 0051',

0 commit comments

Comments
 (0)