Skip to content

Commit 325699a

Browse files
authored
Fix unless rules (#37291)
1 parent eaea47a commit 325699a

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,10 +1466,6 @@ public function validateExcludeUnless($attribute, $value, $parameters)
14661466
{
14671467
$this->requireParameterCount(2, $parameters, 'exclude_unless');
14681468

1469-
if (! Arr::has($this->data, $parameters[0])) {
1470-
return true;
1471-
}
1472-
14731469
[$values, $other] = $this->prepareValuesAndOther($parameters);
14741470

14751471
return in_array($other, $values, is_bool($other) || is_null($other));
@@ -1487,10 +1483,6 @@ public function validateRequiredUnless($attribute, $value, $parameters)
14871483
{
14881484
$this->requireParameterCount(2, $parameters, 'required_unless');
14891485

1490-
if (! Arr::has($this->data, $parameters[0])) {
1491-
return true;
1492-
}
1493-
14941486
[$values, $other] = $this->prepareValuesAndOther($parameters);
14951487

14961488
if (! in_array($other, $values, is_bool($other) || is_null($other))) {

tests/Validation/ValidationValidatorTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,10 @@ public function testRequiredUnless()
11561156
$v = new Validator($trans, ['first' => 'sven'], ['last' => 'required_unless:first,taylor,sven']);
11571157
$this->assertTrue($v->passes());
11581158

1159+
$trans = $this->getIlluminateArrayTranslator();
1160+
$v = new Validator($trans, [], ['bar' => 'required_unless:foo,true']);
1161+
$this->assertTrue($v->fails());
1162+
11591163
$trans = $this->getIlluminateArrayTranslator();
11601164
$v = new Validator($trans, ['foo' => false], ['bar' => 'required_unless:foo,false']);
11611165
$this->assertTrue($v->passes());
@@ -1164,6 +1168,18 @@ public function testRequiredUnless()
11641168
$v = new Validator($trans, ['foo' => false], ['bar' => 'required_unless:foo,true']);
11651169
$this->assertTrue($v->fails());
11661170

1171+
$trans = $this->getIlluminateArrayTranslator();
1172+
$v = new Validator($trans, ['bar' => '1'], ['bar' => 'required_unless:foo,true']);
1173+
$this->assertTrue($v->passes());
1174+
1175+
$trans = $this->getIlluminateArrayTranslator();
1176+
$v = new Validator($trans, [], ['bar' => 'required_unless:foo,true']);
1177+
$this->assertTrue($v->fails());
1178+
1179+
$trans = $this->getIlluminateArrayTranslator();
1180+
$v = new Validator($trans, [], ['bar' => 'required_unless:foo,null']);
1181+
$this->assertTrue($v->passes());
1182+
11671183
$trans = $this->getIlluminateArrayTranslator();
11681184
$v = new Validator($trans, ['foo' => true], ['bar' => 'required_unless:foo,null']);
11691185
$this->assertTrue($v->fails());
@@ -5524,6 +5540,16 @@ public function testExcludeUnless()
55245540
);
55255541
$this->assertTrue($validator->passes());
55265542
$this->assertSame(['foo' => true], $validator->validated());
5543+
5544+
$trans = $this->getIlluminateArrayTranslator();
5545+
$v = new Validator($trans, ['bar' => 'Hello'], ['bar' => 'exclude_unless:foo,true']);
5546+
$this->assertTrue($v->passes());
5547+
$this->assertSame([], $v->validated());
5548+
5549+
$trans = $this->getIlluminateArrayTranslator();
5550+
$v = new Validator($trans, ['bar' => 'Hello'], ['bar' => 'exclude_unless:foo,null']);
5551+
$this->assertTrue($v->passes());
5552+
$this->assertSame(['bar' => 'Hello'], $v->validated());
55275553
}
55285554

55295555
public function testExcludeValuesAreReallyRemoved()

0 commit comments

Comments
 (0)