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

validation message placeholder is not replaced #49841

Closed
Treggats opened this issue Jan 25, 2024 · 2 comments · Fixed by #49861
Closed

validation message placeholder is not replaced #49841

Treggats opened this issue Jan 25, 2024 · 2 comments · Fixed by #49861

Comments

@Treggats
Copy link
Contributor

Laravel Version

10.42.0

PHP Version

8.3

Database Driver & Version

No response

Description

Scenario
Validate a password that fails the max rule.

Using the following password validation settings;

Password::defaults(
    Password::min(8)
        ->max(100)
);

Which results in the following error message

The password must not be greater than :max characters.

The :max placeholder is not replaced.

Steps To Reproduce

Currently this test fails

public function test_password_validation_message(): void
{
    $validationMessage = Validator::make(
        data: ['password' => str_repeat('o', 101)],
        rules: ['password' => Password::default()])
            ->messages()
            ->first();

    self::assertNotSame('The password must not be greater than :max characters.', $validationMessage);
}

Changing \Illuminate\Validation\Rules\Password::max() into this makes this test pass.

    public function max($size)
    {
        $this->max = $size;

        $this->customRules = [
            ...$this->customRules,
            'max:'.$size,
        ];

        return $this;
    }
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@crynobone
Copy link
Member

PR #49861 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants