Skip to content

Commit 5b3cc40

Browse files
authored
[12.x] Revert lowercasing validation message placeholders (#57733)
* Revert lowercasing validation message placeholders * Remove unused import * Opened the wrong file and commited prematurely
1 parent a21ad16 commit 5b3cc40

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Illuminate/Validation/Concerns/ReplacesAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ protected function replaceDoesntContain($message, $attribute, $rule, $parameters
938938
*/
939939
private function replaceWhileKeepingCase(string $message, array $mapping): string
940940
{
941-
$fn = [Str::lower(...), Str::upper(...), Str::ucfirst(...)];
941+
$fn = [fn ($v) => $v, Str::upper(...), Str::ucfirst(...)];
942942

943943
$cases = array_reduce(
944944
array_keys($mapping),

tests/Validation/ValidationValidatorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,12 @@ public function testCapitalizedDisplayableValuesAreReplaced()
639639
$v->messages()->setFormat(':message');
640640
$this->assertSame('The foo field must be accepted when BAR is AAA.', $v->messages()->first('foo'));
641641

642+
$trans = $this->getIlluminateArrayTranslator();
643+
$trans->addLines(['validation.accepted_if' => 'The :attribute field must be accepted when :other is :value.'], 'en');
644+
$v = new Validator($trans, ['foo' => 'no', 'bar' => 'aAa'], ['foo' => 'accepted_if:bar,aAa']);
645+
$this->assertFalse($v->passes());
646+
$this->assertSame('The foo field must be accepted when bar is aAa.', $v->messages()->first('foo'));
647+
642648
// in_array
643649
$trans = $this->getIlluminateArrayTranslator();
644650
$trans->addLines(['validation.in_array' => 'The value of :attribute does not exist in :Other.'], 'en');
@@ -715,6 +721,12 @@ public function testCapitalizedDisplayableValuesAreReplaced()
715721
$this->assertFalse($v->passes());
716722
$this->assertSame('The last field is required unless FIRST is in TAYLOR, SVEN.', $v->messages()->first('last'));
717723

724+
$trans = $this->getIlluminateArrayTranslator();
725+
$trans->addLines(['validation.required_unless' => 'The :attribute field is required unless :other is in :values.'], 'en');
726+
$v = new Validator($trans, ['firstName' => 'dAyle', 'lastName' => ''], ['lastName' => 'RequiredUnless:firstName,tAylor,sVen']);
727+
$this->assertFalse($v->passes());
728+
$this->assertSame('The last name field is required unless first name is in tAylor, sVen.', $v->messages()->first('lastName'));
729+
718730
// required_with
719731
$trans = $this->getIlluminateArrayTranslator();
720732
$trans->addLines(['validation.required_with' => 'The :attribute field is required when :Values is present.'], 'en');
@@ -753,6 +765,12 @@ public function testCapitalizedDisplayableValuesAreReplaced()
753765
$v = new Validator($trans, ['url' => 'laravel.com'], ['url' => 'starts_with:http,https']);
754766
$this->assertFalse($v->passes());
755767
$this->assertSame('The url must start with one of the following values HTTP, HTTPS', $v->messages()->first('url'));
768+
769+
$trans = $this->getIlluminateArrayTranslator();
770+
$trans->addLines(['validation.starts_with' => 'The :attribute must start with one of the following values :values'], 'en');
771+
$v = new Validator($trans, ['url' => 'laravel.com'], ['url' => 'starts_with:hTtp,hTtps']);
772+
$this->assertFalse($v->passes());
773+
$this->assertSame('The url must start with one of the following values hTtp, hTtps', $v->messages()->first('url'));
756774
}
757775

758776
public function testInputIsReplacedByItsDisplayableValue()

0 commit comments

Comments
 (0)