Framework: Passes method of custom validation rule receives array keys with dotPlaceholder

Created on 10 Sep 2020  路  7Comments  路  Source: laravel/framework


  • Laravel Version: 8
  • PHP Version: 7.4
  • Database Driver & Version: n/a

Description:

When validating an array with a custom validation Rule, the $value param of the rule's passes() method receives the array with dot placeholders included in keys. This makes it impossible to validate array keys containing dots.

Related to #33357

Steps To Reproduce:

Send a request with an array query parameter that has keys containing dots e.g. foo[foo.bar]=baz

Validate with a custom validation rule e.g. ['foo' => new CustomRule()]

dd() the $value param of the passes() method and the result will be something like: ['fooP0gffDX4ilGw68H6bar' => 'baz']

All 7 comments

I don't believe we allow dots in input variables during validation because dots have special meaning with array depth validation in Laravel.

Ping @themsaid

I don't believe we allow dots in input variables during validation because dots have special meaning with array depth validation in Laravel.

This worked just fine prior to version 7 with the -> replacement. I realise this was probably undocumented functionality but we found it really useful for creating APIs with relational filters e.g. filter[posts.category.id][is]=5

Fixed in upcoming patch release.

@taylorotwell is this being patched in v7 also?

Issue is still actual for 6.x
@taylorotwell will fix be ported there too ?

Was this page helpful?
0 / 5 - 0 ratings