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

[5.8] Fix database rules with WHERE clauses #28748

Merged
merged 1 commit into from Jun 6, 2019

Conversation

Projects
None yet
2 participants
@staudenmeir
Copy link
Contributor

commented Jun 6, 2019

exists and unique rules fail if a WHERE clause has an empty string value:

Validator::make(
    ['id' => 1],
    ['id' => Rule::exists('users')->where('name', '')]
)->passes();

This throws an exception:

Undefined offset: 1

The error is caused by rtrim(..., , ',') in Exists::__toString():

dump((string) Rule::exists('users')->where('name', ''));

// expected: exists:users,NULL,name,
// actual:   exists:users,NULL,name

The underlying issue is that ValidationRuleParser::parseParameters() parses parameters as CSV, but only receives plain text. This also affects values that can be interpreted as CSV:

Rule::exists('users')->where('name', '"foo"') // where "name" = 'foo'

We can fix it by converting all values to CSV as we do with in and notin rules (#21012).

Fixes #28697.


Theoretically, this can be a breaking change if someone works around the issue by providing CSV values:

 Rule::exists('users')->where('name', '""')

Do we consider cases like this?

@taylorotwell taylorotwell merged commit f76d0e2 into laravel:5.8 Jun 6, 2019

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@staudenmeir staudenmeir deleted the staudenmeir:database-rule branch Jun 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.