diff --git a/Concerns/ValidatesAttributes.php b/Concerns/ValidatesAttributes.php index a2dfb05..4aa80f1 100644 --- a/Concerns/ValidatesAttributes.php +++ b/Concerns/ValidatesAttributes.php @@ -471,10 +471,14 @@ public function validateBetween($attribute, $value, $parameters) { $this->requireParameterCount(2, $parameters, 'between'); - return with( - BigNumber::of($this->getSize($attribute, $value)), - fn ($size) => $size->isGreaterThanOrEqualTo($this->trim($parameters[0])) && $size->isLessThanOrEqualTo($this->trim($parameters[1])) - ); + try { + return with( + BigNumber::of($this->getSize($attribute, $value)), + fn ($size) => $size->isGreaterThanOrEqualTo($this->trim($parameters[0])) && $size->isLessThanOrEqualTo($this->trim($parameters[1])) + ); + } catch (MathException) { + return false; + } } /** @@ -1223,7 +1227,11 @@ public function validateGt($attribute, $value, $parameters) $this->shouldBeNumeric($attribute, 'Gt'); if (is_null($comparedToValue) && (is_numeric($value) && is_numeric($parameters[0]))) { - return BigNumber::of($this->getSize($attribute, $value))->isGreaterThan($this->trim($parameters[0])); + try { + return BigNumber::of($this->getSize($attribute, $value))->isGreaterThan($this->trim($parameters[0])); + } catch (MathException) { + return false; + } } if (is_numeric($parameters[0])) { @@ -1231,14 +1239,22 @@ public function validateGt($attribute, $value, $parameters) } if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) { - return BigNumber::of($this->trim($value))->isGreaterThan($this->trim($comparedToValue)); + try { + return BigNumber::of($this->trim($value))->isGreaterThan($this->trim($comparedToValue)); + } catch (MathException) { + return false; + } } if (! $this->isSameType($value, $comparedToValue)) { return false; } - return $this->getSize($attribute, $value) > $this->getSize($attribute, $comparedToValue); + try { + return $this->getSize($attribute, $value) > $this->getSize($attribute, $comparedToValue); + } catch (MathException) { + return false; + } } /** @@ -1258,7 +1274,11 @@ public function validateLt($attribute, $value, $parameters) $this->shouldBeNumeric($attribute, 'Lt'); if (is_null($comparedToValue) && (is_numeric($value) && is_numeric($parameters[0]))) { - return BigNumber::of($this->getSize($attribute, $value))->isLessThan($this->trim($parameters[0])); + try { + return BigNumber::of($this->getSize($attribute, $value))->isLessThan($this->trim($parameters[0])); + } catch (MathException) { + return false; + } } if (is_numeric($parameters[0])) { @@ -1273,7 +1293,11 @@ public function validateLt($attribute, $value, $parameters) return false; } - return $this->getSize($attribute, $value) < $this->getSize($attribute, $comparedToValue); + try { + return $this->getSize($attribute, $value) < $this->getSize($attribute, $comparedToValue); + } catch (MathException) { + return false; + } } /** @@ -1293,7 +1317,11 @@ public function validateGte($attribute, $value, $parameters) $this->shouldBeNumeric($attribute, 'Gte'); if (is_null($comparedToValue) && (is_numeric($value) && is_numeric($parameters[0]))) { - return BigNumber::of($this->getSize($attribute, $value))->isGreaterThanOrEqualTo($this->trim($parameters[0])); + try { + return BigNumber::of($this->getSize($attribute, $value))->isGreaterThanOrEqualTo($this->trim($parameters[0])); + } catch (MathException) { + return false; + } } if (is_numeric($parameters[0])) { @@ -1301,14 +1329,22 @@ public function validateGte($attribute, $value, $parameters) } if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) { - return BigNumber::of($this->trim($value))->isGreaterThanOrEqualTo($this->trim($comparedToValue)); + try { + return BigNumber::of($this->trim($value))->isGreaterThanOrEqualTo($this->trim($comparedToValue)); + } catch (MathException) { + return false; + } } if (! $this->isSameType($value, $comparedToValue)) { return false; } - return $this->getSize($attribute, $value) >= $this->getSize($attribute, $comparedToValue); + try { + return $this->getSize($attribute, $value) >= $this->getSize($attribute, $comparedToValue); + } catch (MathException) { + return false; + } } /** @@ -1328,7 +1364,11 @@ public function validateLte($attribute, $value, $parameters) $this->shouldBeNumeric($attribute, 'Lte'); if (is_null($comparedToValue) && (is_numeric($value) && is_numeric($parameters[0]))) { - return BigNumber::of($this->getSize($attribute, $value))->isLessThanOrEqualTo($this->trim($parameters[0])); + try { + return BigNumber::of($this->getSize($attribute, $value))->isLessThanOrEqualTo($this->trim($parameters[0])); + } catch (MathException) { + return false; + } } if (is_numeric($parameters[0])) { @@ -1343,7 +1383,11 @@ public function validateLte($attribute, $value, $parameters) return false; } - return $this->getSize($attribute, $value) <= $this->getSize($attribute, $comparedToValue); + try { + return $this->getSize($attribute, $value) <= $this->getSize($attribute, $comparedToValue); + } catch (MathException) { + return false; + } } /** @@ -1544,7 +1588,11 @@ public function validateMax($attribute, $value, $parameters) return false; } - return BigNumber::of($this->getSize($attribute, $value))->isLessThanOrEqualTo($this->trim($parameters[0])); + try { + return BigNumber::of($this->getSize($attribute, $value))->isLessThanOrEqualTo($this->trim($parameters[0])); + } catch (MathException) { + return false; + } } /** @@ -1646,7 +1694,11 @@ public function validateMin($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'min'); - return BigNumber::of($this->getSize($attribute, $value))->isGreaterThanOrEqualTo($this->trim($parameters[0])); + try { + return BigNumber::of($this->getSize($attribute, $value))->isGreaterThanOrEqualTo($this->trim($parameters[0])); + } catch (MathException) { + return false; + } } /** @@ -2466,7 +2518,11 @@ public function validateSize($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'size'); - return BigNumber::of($this->getSize($attribute, $value))->isEqualTo($this->trim($parameters[0])); + try { + return BigNumber::of($this->getSize($attribute, $value))->isEqualTo($this->trim($parameters[0])); + } catch (MathException) { + return false; + } } /** @@ -2738,6 +2794,8 @@ protected function trim($value) * @param string $attribute * @param mixed $value * @return mixed + * + * @throws \Illuminate\Support\Exceptions\MathException */ protected function ensureExponentWithinAllowedRange($attribute, $value) { diff --git a/Validator.php b/Validator.php index 21cb2e7..39e259a 100755 --- a/Validator.php +++ b/Validator.php @@ -1657,6 +1657,16 @@ protected function callClassBasedExtension($callback, $parameters) return $this->container->make($class)->{$method}(...array_values($parameters)); } + /** + * Flush the validator's global state. + * + * @return void + */ + public static function flushState() + { + static::$placeholderHash = null; + } + /** * Handle dynamic calls to class methods. * diff --git a/composer.json b/composer.json index ac4f997..6ff9711 100755 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "php": "^8.2", "ext-filter": "*", "ext-mbstring": "*", - "brick/math": "^0.9.3|^0.10.2|^0.11|^0.12", + "brick/math": "^0.9.3|^0.10.2|^0.11|^0.12|^0.13|^0.14", "egulias/email-validator": "^3.2.5|^4.0", "illuminate/collections": "^11.0", "illuminate/container": "^11.0",