Skip to content

Commit 0d1ac32

Browse files
authored
Merge pull request #33932 from klimov-paul/33357-fix-validator-dot-replace
[7.x ] Fix key composition for attribute with dot at validation error messages
2 parents 56d2fec + f9b9fda commit 0d1ac32

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Illuminate/Validation/Validator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,11 @@ public function addFailure($attribute, $rule, $parameters = [])
776776
$this->passes();
777777
}
778778

779-
$attribute = str_replace('__asterisk__', '*', $attribute);
779+
$attribute = str_replace(
780+
[$this->dotPlaceholder, '__asterisk__'],
781+
['.', '*'],
782+
$attribute
783+
);
780784

781785
if (in_array($rule, $this->excludeRules)) {
782786
return $this->excludeAttribute($attribute);

tests/Validation/ValidationValidatorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,6 +3953,15 @@ public function testPlaceholdersAreReplaced()
39533953
'foo\.bar' => 'required|in:valid',
39543954
]);
39553955
$this->assertTrue($v->fails());
3956+
$this->assertArrayHasKey('foo.bar', $v->errors()->getMessages());
3957+
3958+
$v = new Validator($trans, [
3959+
'foo.bar' => 'valid',
3960+
], [
3961+
'foo\.bar' => 'required|in:valid',
3962+
]);
3963+
$this->assertTrue($v->passes());
3964+
$this->assertArrayHasKey('foo.bar', $v->validated());
39563965
}
39573966

39583967
public function testCoveringEmptyKeys()

0 commit comments

Comments
 (0)