Skip to content

Commit

Permalink
Merge pull request #8088 from kenjis/fix-validation-exact_length
Browse files Browse the repository at this point in the history
fix: [Validation] exact_length does not pass int values
  • Loading branch information
kenjis authored Oct 25, 2023
2 parents b92057c + 391723b commit f780d75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
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

0 comments on commit f780d75

Please sign in to comment.