From 04e780697ae5bf3dc65cf06e57e96c1f3fd99696 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 16 Mar 2022 14:16:20 +0900 Subject: [PATCH] fix: TypeError when the field is not sent TypeError: CodeIgniter\Validation\FormatRules::valid_date(): Argument #1 ($str) must be of type string, null given --- system/Validation/FormatRules.php | 4 ++++ tests/system/Validation/FormatRulesTest.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/system/Validation/FormatRules.php b/system/Validation/FormatRules.php index 990ea8128809..676ae8485ba2 100644 --- a/system/Validation/FormatRules.php +++ b/system/Validation/FormatRules.php @@ -333,6 +333,10 @@ public function valid_url_strict(?string $str = null, ?string $validSchemes = nu */ public function valid_date(?string $str = null, ?string $format = null): bool { + if (($str === null)) { + return false; + } + if (empty($format)) { return strtotime($str) !== false; } diff --git a/tests/system/Validation/FormatRulesTest.php b/tests/system/Validation/FormatRulesTest.php index f4a22b2af973..bf9bf92eb6dc 100644 --- a/tests/system/Validation/FormatRulesTest.php +++ b/tests/system/Validation/FormatRulesTest.php @@ -1206,6 +1206,11 @@ public function testValidDate(?string $str, ?string $format, bool $expected): vo public function validDateProvider(): Generator { yield from [ + [ + null, + 'Y-m-d', + false, + ], [ 'Sun', 'D',