Skip to content

Commit f768d16

Browse files
committed
fix: TypeError when the value is not int or string
1 parent a7c42cd commit f768d16

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

system/Validation/StrictRules/Rules.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public function greater_than($str, string $min): bool
7979
$str = (string) $str;
8080
}
8181

82+
if (! is_string($str)) {
83+
return false;
84+
}
85+
8286
return $this->nonStrictRules->greater_than($str, $min);
8387
}
8488

@@ -93,6 +97,10 @@ public function greater_than_equal_to($str, string $min): bool
9397
$str = (string) $str;
9498
}
9599

100+
if (! is_string($str)) {
101+
return false;
102+
}
103+
96104
return $this->nonStrictRules->greater_than_equal_to($str, $min);
97105
}
98106

@@ -157,6 +165,10 @@ public function less_than($str, string $max): bool
157165
$str = (string) $str;
158166
}
159167

168+
if (! is_string($str)) {
169+
return false;
170+
}
171+
160172
return $this->nonStrictRules->less_than($str, $max);
161173
}
162174

@@ -171,6 +183,10 @@ public function less_than_equal_to($str, string $max): bool
171183
$str = (string) $str;
172184
}
173185

186+
if (! is_string($str)) {
187+
return false;
188+
}
189+
174190
return $this->nonStrictRules->less_than_equal_to($str, $max);
175191
}
176192

tests/system/Validation/StrictRules/RulesTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function provideGreaterThanEqualStrict(): Generator
104104
[0, '0', true],
105105
[1, '0', true],
106106
[-1, '0', false],
107+
[true, '0', false],
107108
];
108109
}
109110

@@ -127,6 +128,7 @@ public function provideGreaterThanStrict(): Generator
127128
[10, '9', true],
128129
[10, '10', false],
129130
[10, 'a', false],
131+
[true, '0', false],
130132
];
131133
}
132134

@@ -151,6 +153,7 @@ public function provideLessThanStrict(): Generator
151153
[10, '9', false],
152154
[10, '10', false],
153155
[10, 'a', true],
156+
[true, '0', false],
154157
];
155158
}
156159

@@ -173,6 +176,7 @@ public function provideLessThanEqualStrict(): Generator
173176
[0, '0', true],
174177
[1, '0', false],
175178
[-1, '0', true],
179+
[true, '0', false],
176180
];
177181
}
178182
}

0 commit comments

Comments
 (0)