Skip to content

Validation: empty string passes the array rule #41734

@danilopolani

Description

@danilopolani
  • Laravel Version: 9.5.1
  • PHP Version: 8.1.3
  • Database Driver & Version: Not relevant

Description:

Using an empty string as value for the array rule passes but it should not.

Note: this is an intentional duplicate of #18948, but since that issue has never been solved I decided to open a new one. In that issue there was a discussion about ConvertEmptyStringsToNull but that's incorrect, since we could use the validation outside of HTTP requests.

Steps To Reproduce:

\Validator::make(['field' => ''], ['field' => 'present|array'])->fails(); // false, WRONG

\Validator::make(['field' => null], ['field' => 'present|array'])->fails(); // true, correct
\Validator::make(['field' => 0], ['field' => 'present|array'])->fails(); // true, correct
\Validator::make(['field' => false], ['field' => 'present|array'])->fails(); // true, correct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions