Skip to content

Commit

Permalink
Merge pull request #33932 from klimov-paul/33357-fix-validator-dot-re…
Browse files Browse the repository at this point in the history
…place

[7.x ] Fix key composition for attribute with dot at validation error messages
  • Loading branch information
themsaid committed Aug 19, 2020
2 parents 56d2fec + f9b9fda commit 0d1ac32
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
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
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 0d1ac32

Please sign in to comment.