Skip to content

Commit

Permalink
Fix matching custom validation messages via exact (#15557)
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid authored and taylorotwell committed Sep 22, 2016
1 parent 4532598 commit b9511bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,7 @@ protected function getCustomMessageFromTranslator($customKey)
);

foreach ($customMessages as $key => $message) {
if (Str::contains($key, ['*']) && Str::is($key, $shortKey)) {
if ($shortKey === $key || (Str::contains($key, ['*']) && Str::is($key, $shortKey))) {
return $message;
}
}
Expand Down
7 changes: 6 additions & 1 deletion tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,19 @@ public function testCustomValidationLinesAreRespectedWithAsterisks()
'name.*' => [
'required' => 'all are really required!',
],
'lang.en' => [
'required' => 'english is required!',
],
],
]);
$v = new Validator($trans, ['name' => ['', '']], []);
$v = new Validator($trans, ['name' => ['', ''], 'lang' => ['en' => '']], []);
$v->each('name', 'required|max:255');
$v->each('lang.*', 'required|max:255');
$this->assertFalse($v->passes());
$v->messages()->setFormat(':message');
$this->assertEquals('all are really required!', $v->messages()->first('name.0'));
$this->assertEquals('all are really required!', $v->messages()->first('name.1'));
$this->assertEquals('english is required!', $v->messages()->first('lang.en'));
}

public function testValidationDotCustomDotAnythingCanBeTranslated()
Expand Down

0 comments on commit b9511bf

Please sign in to comment.