From b3a94fe0742c10f095cde4ab3cf92b2dec11a12a Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Thu, 30 Jul 2020 19:33:40 +0200 Subject: [PATCH] ignore numeric field names --- .../Validation/Concerns/ValidatesAttributes.php | 16 ++++++++++++++++ tests/Validation/ValidationValidatorTest.php | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index a7c1e6665011..1d3f575e516d 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -933,6 +933,10 @@ public function validateGt($attribute, $value, $parameters) return $this->getSize($attribute, $value) > $parameters[0]; } + if (is_numeric($parameters[0])) { + return false; + } + if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) { return $value > $comparedToValue; } @@ -964,6 +968,10 @@ public function validateLt($attribute, $value, $parameters) return $this->getSize($attribute, $value) < $parameters[0]; } + if (is_numeric($parameters[0])) { + return false; + } + if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) { return $value < $comparedToValue; } @@ -995,6 +1003,10 @@ public function validateGte($attribute, $value, $parameters) return $this->getSize($attribute, $value) >= $parameters[0]; } + if (is_numeric($parameters[0])) { + return false; + } + if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) { return $value >= $comparedToValue; } @@ -1026,6 +1038,10 @@ public function validateLte($attribute, $value, $parameters) return $this->getSize($attribute, $value) <= $parameters[0]; } + if (is_numeric($parameters[0])) { + return false; + } + if ($this->hasRule($attribute, $this->numericRules) && is_numeric($value) && is_numeric($comparedToValue)) { return $value <= $comparedToValue; } diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 16cbd24c1e2d..e50f78427fdf 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1280,6 +1280,9 @@ public function testGreaterThan() $v = new Validator($trans, ['lhs' => 15.0], ['lhs' => 'numeric|gt:10']); $this->assertTrue($v->passes()); + $v = new Validator($trans, ['lhs' => 5, 10 => 1], ['lhs' => 'numeric|gt:10']); + $this->assertTrue($v->fails()); + $v = new Validator($trans, ['lhs' => '15'], ['lhs' => 'numeric|gt:10']); $this->assertTrue($v->passes());