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

[8.x] Retain the original attribute value during validation of an array key with a dot for correct failure message #42395

Merged
merged 2 commits into from
May 24, 2022

Conversation

chiefey
Copy link
Contributor

@chiefey chiefey commented May 16, 2022

During validation of an array key with a dot, using a integer|min:1 rule - the package will incorrectly return validation.min.string instead of the expected validation.min.numeric.

Illuminate\Validation\Validator replaces the placeholder in the attribute a bit prematurely in the addFailure function.

Code will continue to makeReplacements, getMessage, getSizeMessage, getAttributeType, hasRule, getRule

You can see down the line you are searching a with-placeholder rules array for a without-placeholder key. When the numeric search fails, it will default to string.

My fix retains that original attribute value including the placeholder to return the expected failure message

@GrahamCampbell GrahamCampbell changed the title Retain the original attribute value during validation of an array key with a dot for correct failure message [8.x] Retain the original attribute value during validation of an array key with a dot for correct failure message May 16, 2022
@taylorotwell
Copy link
Member

I don't think it makes sense to keep the place-holders in place when passing the attribute name to getMessage? It then checks the custom attribute array for that attribute using the place-holders, which doesn't make sense to me.

@taylorotwell taylorotwell marked this pull request as draft May 16, 2022 15:30
@chiefey
Copy link
Contributor Author

chiefey commented May 16, 2022

@taylorotwell ok if we are worried about the custom attributes - I will isolate this change to the getSizeMessage path inside getMessage and resubmit.

@chiefey chiefey marked this pull request as ready for review May 16, 2022 20:51
@chiefey
Copy link
Contributor Author

chiefey commented May 16, 2022

With this update the custom attribute array is left as-is. Only the getSizeMessage path uses the attributeWithPlaceholders value.

In this way we prevent a call to getRule with a cleaned attribute value.

@taylorotwell taylorotwell merged commit aabf205 into laravel:8.x May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants