Skip to content

Commit c5e3d3c

Browse files
Fixed validate rule date does not work as expected when the value isn't string. (#3959)
* Added suggest requirement for `hyperf/database`. * Added test cases Co-authored-by: 李铭昕 <[email protected]>
1 parent 70910f5 commit c5e3d3c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Concerns/ValidatesAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function validateDate(string $attribute, $value): bool
220220
return true;
221221
}
222222

223-
if ((! is_string($value) && ! is_numeric($value)) || strtotime($value) === false) {
223+
if ((! is_string($value) && ! is_numeric($value)) || strtotime((string) $value) === false) {
224224
return false;
225225
}
226226

tests/Cases/ValidateAttributesTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,11 @@ public function testValidateAlphaNum()
6161
$this->assertFalse($validator->validateAlphaNum('', '123_f1'));
6262
$this->assertFalse($validator->validateAlphaNum('', 'xxx_yy'));
6363
}
64+
65+
public function testValidateDate()
66+
{
67+
$validator = new ValidatesAttributesStub();
68+
69+
$this->assertFalse($validator->validateDate('', 123));
70+
}
6471
}

0 commit comments

Comments
 (0)