Repository navigation
Conversation
…ation paths resolveStaticCollectionRules() built each item's rule path directly from the array key. Laravel's validator reads dots in a rule path as nested segment separators, so a literal dot in a keyed collection's key (e.g. translations['en.greeting']) got misread as translations.en.greeting.*, pointing rule generation at the wrong path and reporting a valid payload as missing the field. Escape the key the same way Laravel's own dot-notation rules do (\.) before appending it to the path. Fixes spatie#1198
Author
|
Hi @rubenvanassche, small ping on this one. It fixes #1198: a dot inside an array key gets treated as a path separator when validating keyed collections. It's the same one-line fix @lazerg proposed in #1199, which closed without review, and @lazerg is fine with this PR carrying it forward. The Run Tests and PHPStan checks show as failed, but they never ran. They were waiting for approval and GitHub marked them failed after 30 days. Could you approve or re-run them when you get a chance? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1198.
A keyed collection (
array<string, ChildData>) fails validation when one of the array keys contains a literal dot.resolveStaticCollectionRules()builds the rule path straight from the key, soen.greetingends up as the rule attributetranslations.en.greeting.stringwhileValidator::parseData()has already turned the matching data key into an internal placeholder — the attribute never resolves against the payload, andrequiredfails even though the field is there.This escapes the key with
\.before it's appended to the path, which is whatValidator::encodeAttributeWithPlaceholder()already recognizes for rule attributes.Scope: this covers the static rules branch only;
resolveDynamicCollectionRules()(theRule::forEachpath) isn't touched. It also only fixes rule generation — payload introspection elsewhere in this resolver still reads keys throughArr::get()/Arr::has(), which doesn't understand the escaped form, so anOptional, nullable, or nested property under a dotted key isn't fixed by this PR (not a regression from this change, just not covered by it).Added a test that reproduces the bug directly. Full suite still passes (1322 tests, 0 failures).
#1199 proposed the same one-line change in July. It sat without maintainer review and closed without merging. I arrived at the same fix independently and added the regression test — credit to @lazerg for finding it first, I've linked this PR from that thread.