Skip to content
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 @@ -493,7 +493,7 @@ public function validateBoolean($attribute, $value, $parameters)
{
$acceptable = [true, false, 0, 1, '0', '1'];

if (($parameters[0] ?? null) === 'strict') {
if (isset($parameters[0]) && strtolower($parameters[0]) === 'strict') {
$acceptable = [true, false];
}

Expand Down
76 changes: 76 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,44 @@ public function testValidateBooleanStrict()
$this->assertFalse($v->passes());
}

public function testValidateBooleanStrictWithUpperCase()
{
$trans = $this->getIlluminateArrayTranslator();

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

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

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

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

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

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

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

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

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

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

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

public function testValidateBool()
{
$trans = $this->getIlluminateArrayTranslator();
Expand Down Expand Up @@ -3229,6 +3267,44 @@ public function testValidateBoolStrict()
$this->assertFalse($v->passes());
}

public function testValidateBoolStrictWithUpperCase()
{
$trans = $this->getIlluminateArrayTranslator();

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

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

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

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

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

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

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

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

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

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

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

public function testValidateNumeric()
{
$trans = $this->getIlluminateArrayTranslator();
Expand Down