Skip to content

Commit 37cb3b8

Browse files
fix(LengthValidator): don't validate maximum if no maximum is given
This commit allows the maximum constraint to be entirely bypassed by setting the maximum property to 0 as some cases will not have a static maximum value.
1 parent 337ebc3 commit 37cb3b8

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Validators/LengthValidator.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class LengthValidator extends RESTAPI\Core\Validator {
4444
);
4545
}
4646
# Throw an error if the string contains more characters than the specified maximum
47-
if (strlen($value) > $this->maximum) {
47+
if ($this->maximum and strlen($value) > $this->maximum) {
4848
throw new ValidationError(
4949
message: "Field '$field_name' exceeds the maximum character length of $this->maximum.",
5050
response_id: 'LENGTH_VALIDATOR_MAXIMUM_CONSTRAINT',
@@ -61,7 +61,7 @@ class LengthValidator extends RESTAPI\Core\Validator {
6161
);
6262
}
6363
# Throw an error if the array contains more array entries than the specified maximum
64-
if (count($value) > $this->maximum) {
64+
if ($this->maximum and count($value) > $this->maximum) {
6565
throw new ValidationError(
6666
message: "Field '$field_name' exceeds the maximum array length of $this->maximum.",
6767
response_id: 'LENGTH_VALIDATOR_MAXIMUM_CONSTRAINT',

0 commit comments

Comments
 (0)