Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Fix matching custom validation messages via exact #15557

Merged
merged 1 commit into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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