Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Validation/CreditCardRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function valid_cc_number(?string $ccNumber, string $type): bool
$ccNumber = str_replace([' ', '-'], '', $ccNumber);

// Non-numeric values cannot be a number...duh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Non-numeric values cannot be a number...duh
// Reject non-digit characters before running the Luhn check.

Or remove the comment entirely, since the ctype_digit() check and early return are already self-explanatory.

if (! is_numeric($ccNumber)) {
if (! ctype_digit($ccNumber)) {
return false;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/system/Validation/StrictRules/CreditCardRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ public static function provideValidCCNumber(): iterable
'abcd efgh ijkl mnop',
false,
],
'decimal_point_visa' => [
'visa',
'41.1111111111111',
false,
],
'decimal_point_mastercard' => [
'mastercard',
'5351367.37861108',
false,
],
'bad_length' => [
'amex',
'3782 8224 6310 0051',
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.7.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Bugs Fixed
- **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden).
- **I18n:** Fixed a bug where ``Time::today()``, ``Time::yesterday()``, and ``Time::tomorrow()`` ignored the specified ``$timezone`` and ``setTestNow()`` when calculating the day.
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
- **Validation:** Fixed a bug where ``valid_cc_number`` accepted non-digit characters (e.g., a decimal point) in the card number. Such values could pass the Luhn check and triggered an ``Undefined array key`` warning inside it; the number is now checked with ``ctype_digit()``.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down
Loading