Skip to content

Commit

Permalink
fix: TypeError when the field is not sent
Browse files Browse the repository at this point in the history
TypeError: CodeIgniter\Validation\FormatRules::valid_date(): Argument #1 ($str) must be of type string, null given
  • Loading branch information
kenjis committed Mar 16, 2022
1 parent 6277232 commit 04e7806
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions system/Validation/FormatRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/system/Validation/FormatRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 04e7806

Please sign in to comment.