diff --git a/system/Validation/StrictRules/Rules.php b/system/Validation/StrictRules/Rules.php index 7043646c1f58..0887eff28ada 100644 --- a/system/Validation/StrictRules/Rules.php +++ b/system/Validation/StrictRules/Rules.php @@ -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; } diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index f031a129a286..23358d08904b 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -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])); @@ -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], ]; }