Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added support for "true" and "false" text values to the Boolean validation rule for compatibility with FormData #43955

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public function validateBetween($attribute, $value, $parameters)
*/
public function validateBoolean($attribute, $value)
{
$acceptable = [true, false, 0, 1, '0', '1'];
$acceptable = [true, false, 'true', 'false', 0, 1, '0', '1'];

return in_array($value, $acceptable, true);
}
Expand Down
26 changes: 22 additions & 4 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2221,10 +2221,10 @@ public function testValidateBoolean()
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => 'false'], ['foo' => 'Boolean']);
$this->assertFalse($v->passes());
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => 'true'], ['foo' => 'Boolean']);
$this->assertFalse($v->passes());
$this->assertTrue($v->passes());

$v = new Validator($trans, [], ['foo' => 'Boolean']);
$this->assertTrue($v->passes());
Expand All @@ -2246,6 +2246,15 @@ public function testValidateBoolean()

$v = new Validator($trans, ['foo' => 0], ['foo' => 'Boolean']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => 'bar'], ['foo' => 'Boolean']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => []], ['foo' => 'Boolean']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => new NonEloquentModel()], ['foo' => 'Boolean']);
$this->assertFalse($v->passes());
}

public function testValidateBool()
Expand All @@ -2258,10 +2267,10 @@ public function testValidateBool()
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => 'false'], ['foo' => 'Bool']);
$this->assertFalse($v->passes());
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => 'true'], ['foo' => 'Bool']);
$this->assertFalse($v->passes());
$this->assertTrue($v->passes());

$v = new Validator($trans, [], ['foo' => 'Bool']);
$this->assertTrue($v->passes());
Expand All @@ -2283,6 +2292,15 @@ public function testValidateBool()

$v = new Validator($trans, ['foo' => 0], ['foo' => 'Bool']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => 'bar'], ['foo' => 'Bool']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => []], ['foo' => 'Bool']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => new NonEloquentModel()], ['foo' => 'Bool']);
$this->assertFalse($v->passes());
}

public function testValidateNumeric()
Expand Down