Skip to content

Commit 3be80cb

Browse files
authored
Merge pull request #6492 from kenjis/fix-validation-greater_than_equal_to
fix: Strict Validation Rules greater_than/less_than
2 parents 836a5aa + f768d16 commit 3be80cb

File tree

3 files changed

+95
-499
lines changed

3 files changed

+95
-499
lines changed

system/Validation/StrictRules/Rules.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,36 @@ public function exact_length($str, string $val): bool
7171
/**
7272
* Greater than
7373
*
74-
* @param mixed $str
74+
* @param mixed $str expects int|string
7575
*/
7676
public function greater_than($str, string $min): bool
7777
{
78+
if (is_int($str)) {
79+
$str = (string) $str;
80+
}
81+
82+
if (! is_string($str)) {
83+
return false;
84+
}
85+
7886
return $this->nonStrictRules->greater_than($str, $min);
7987
}
8088

8189
/**
8290
* Equal to or Greater than
8391
*
84-
* @param mixed $str
92+
* @param mixed $str expects int|string
8593
*/
8694
public function greater_than_equal_to($str, string $min): bool
8795
{
96+
if (is_int($str)) {
97+
$str = (string) $str;
98+
}
99+
100+
if (! is_string($str)) {
101+
return false;
102+
}
103+
88104
return $this->nonStrictRules->greater_than_equal_to($str, $min);
89105
}
90106

@@ -141,20 +157,36 @@ public function is_unique($str, string $field, array $data): bool
141157
/**
142158
* Less than
143159
*
144-
* @param mixed $str
160+
* @param mixed $str expects int|string
145161
*/
146162
public function less_than($str, string $max): bool
147163
{
164+
if (is_int($str)) {
165+
$str = (string) $str;
166+
}
167+
168+
if (! is_string($str)) {
169+
return false;
170+
}
171+
148172
return $this->nonStrictRules->less_than($str, $max);
149173
}
150174

151175
/**
152176
* Equal to or Less than
153177
*
154-
* @param mixed $str
178+
* @param mixed $str expects int|string
155179
*/
156180
public function less_than_equal_to($str, string $max): bool
157181
{
182+
if (is_int($str)) {
183+
$str = (string) $str;
184+
}
185+
186+
if (! is_string($str)) {
187+
return false;
188+
}
189+
158190
return $this->nonStrictRules->less_than_equal_to($str, $max);
159191
}
160192

tests/system/Validation/RulesTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
/**
2121
* @internal
22+
*
23+
* @no-final
2224
*/
23-
final class RulesTest extends CIUnitTestCase
25+
class RulesTest extends CIUnitTestCase
2426
{
25-
private Validation $validation;
26-
private array $config = [
27+
protected Validation $validation;
28+
protected array $config = [
2729
'ruleSets' => [
2830
Rules::class,
2931
FormatRules::class,

0 commit comments

Comments
 (0)