Skip to content

Commit

Permalink
#33357: fix key composition for attribute with dot at validation erro…
Browse files Browse the repository at this point in the history
…r messages
  • Loading branch information
klimov-paul committed Aug 19, 2020
1 parent 99c74a8 commit 7e0cb20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,11 @@ public function addFailure($attribute, $rule, $parameters = [])
$this->passes();
}

$attribute = str_replace('__asterisk__', '*', $attribute);
$attribute = str_replace(
[$this->dotPlaceholder, '__asterisk__'],
['.', '*'],
$attribute
);

if (in_array($rule, $this->excludeRules)) {
return $this->excludeAttribute($attribute);
Expand Down
9 changes: 9 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3953,6 +3953,15 @@ public function testPlaceholdersAreReplaced()
'foo\.bar' => 'required|in:valid',
]);
$this->assertTrue($v->fails());
$this->assertArrayHasKey('foo.bar', $v->errors()->getMessages());

$v = new Validator($trans, [
'foo.bar' => 'valid'
], [
'foo\.bar' => 'required|in:valid',
]);
$this->assertTrue($v->passes());
$this->assertArrayHasKey('foo.bar', $v->validated());
}

public function testCoveringEmptyKeys()
Expand Down

0 comments on commit 7e0cb20

Please sign in to comment.