Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [Validation] exact_length does not pass int values #8088

Merged
merged 2 commits into from
Oct 25, 2023
Merged
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
4 changes: 4 additions & 0 deletions system/Validation/StrictRules/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function equals($str, string $val): bool
*/
public function exact_length($str, string $val): bool
{
if (is_int($str) || is_float($str)) {
$str = (string) $str;
}

if (! is_string($str)) {
return false;
}
Expand Down
15 changes: 10 additions & 5 deletions tests/system/Validation/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,10 @@ public function testMaxLengthReturnsFalseWithNonNumericVal(): void

/**
* @dataProvider provideExactLength
*
* @param int|string|null $data
*/
public function testExactLength(?string $data, bool $expected): void
public function testExactLength($data, bool $expected): void
{
$this->validation->setRules(['foo' => 'exact_length[3]']);
$this->assertSame($expected, $this->validation->run(['foo' => $data]));
Expand All @@ -408,10 +410,13 @@ public function testExactLength(?string $data, bool $expected): void
public static function provideExactLength(): iterable
{
yield from [
'null' => [null, false],
'exact' => ['bar', true],
'less' => ['ba', false],
'greater' => ['bars', false],
'null' => [null, false],
'exact' => ['bar', true],
'exact_int' => [123, true],
'less' => ['ba', false],
'less_int' => [12, false],
'greater' => ['bars', false],
'greater_int' => [1234, false],
];
}

Expand Down
Loading