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
Merged

[5.8] Fix database rules with WHERE clauses #28748

merged 1 commit into from
Jun 6, 2019

Conversation

staudenmeir
Copy link
Contributor

@staudenmeir staudenmeir 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
@staudenmeir staudenmeir deleted the database-rule branch June 6, 2019 14:08
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.

getExtraConditions Validation Undefined Offset: 1 Fault
2 participants