Skip to content

Commit

Permalink
revert digits changes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 26, 2022
1 parent a4723ec commit c113768
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 63 deletions.
22 changes: 1 addition & 21 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,18 +563,7 @@ public function validateDigits($attribute, $value, $parameters)
{
$this->requireParameterCount(1, $parameters, 'digits');

$length = strlen((string) $value);

if (((string) $value) === '.') {
return false;
}

// Make sure there is not more than one dot...
if (($length - strlen(str_replace('.', '', (string) $value))) > 1) {
return false;
}

return ! preg_match('/[^0-9.]/', $value)
return ! preg_match('/[^0-9]/', $value)
&& strlen((string) $value) == $parameters[0];
}

Expand All @@ -592,15 +581,6 @@ public function validateDigitsBetween($attribute, $value, $parameters)

$length = strlen((string) $value);

if (((string) $value) === '.') {
return false;
}

// Make sure there is not more than one dot...
if (($length - strlen(str_replace('.', '', (string) $value))) > 1) {
return false;
}

return ! preg_match('/[^0-9.]/', $value)
&& $length >= $parameters[0] && $length <= $parameters[1];
}
Expand Down
42 changes: 0 additions & 42 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2325,30 +2325,6 @@ public function testValidateDigits()
$v = new Validator($trans, ['foo' => '2e7'], ['foo' => 'Digits:3']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '1.2'], ['foo' => 'digits:3']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => '0.9876'], ['foo' => 'digits:5']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '1..2'], ['foo' => 'digits:4']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '123.456.789'], ['foo' => 'digits:10']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '...'], ['foo' => 'digits:3']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '.'], ['foo' => 'digits:1']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '.2'], ['foo' => 'digits:2']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => '2.'], ['foo' => 'digits:2']);
$this->assertTrue($v->passes());

$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['foo' => '12345'], ['foo' => 'digits_between:1,6']);
$this->assertTrue($v->passes());
Expand All @@ -2367,24 +2343,6 @@ public function testValidateDigits()

$v = new Validator($trans, ['foo' => '0.9876'], ['foo' => 'digits_between:1,5']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '1..2'], ['foo' => 'digits_between:1,10']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '123.456.789'], ['foo' => 'digits_between:1,10']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '...'], ['foo' => 'digits_between:1,10']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '.'], ['foo' => 'digits_between:1,10']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['foo' => '.2'], ['foo' => 'digits_between:0,10']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => '2.'], ['foo' => 'digits_between:1,10']);
$this->assertTrue($v->passes());
}

public function testValidateSize()
Expand Down

1 comment on commit c113768

@taai
Copy link
Contributor

@taai taai commented on c113768 May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorotwell The dot is still there in regex in validateDigitsBetween(). Please revert also the PR that caused all this: #40278

Please sign in to comment.