Skip to content

Commit f780d75

Browse files
authored
Merge pull request #8088 from kenjis/fix-validation-exact_length
fix: [Validation] exact_length does not pass int values
2 parents b92057c + 391723b commit f780d75

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

system/Validation/StrictRules/Rules.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function equals($str, string $val): bool
6363
*/
6464
public function exact_length($str, string $val): bool
6565
{
66+
if (is_int($str) || is_float($str)) {
67+
$str = (string) $str;
68+
}
69+
6670
if (! is_string($str)) {
6771
return false;
6872
}

tests/system/Validation/RulesTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,10 @@ public function testMaxLengthReturnsFalseWithNonNumericVal(): void
398398

399399
/**
400400
* @dataProvider provideExactLength
401+
*
402+
* @param int|string|null $data
401403
*/
402-
public function testExactLength(?string $data, bool $expected): void
404+
public function testExactLength($data, bool $expected): void
403405
{
404406
$this->validation->setRules(['foo' => 'exact_length[3]']);
405407
$this->assertSame($expected, $this->validation->run(['foo' => $data]));
@@ -408,10 +410,13 @@ public function testExactLength(?string $data, bool $expected): void
408410
public static function provideExactLength(): iterable
409411
{
410412
yield from [
411-
'null' => [null, false],
412-
'exact' => ['bar', true],
413-
'less' => ['ba', false],
414-
'greater' => ['bars', false],
413+
'null' => [null, false],
414+
'exact' => ['bar', true],
415+
'exact_int' => [123, true],
416+
'less' => ['ba', false],
417+
'less_int' => [12, false],
418+
'greater' => ['bars', false],
419+
'greater_int' => [1234, false],
415420
];
416421
}
417422

0 commit comments

Comments
 (0)