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] Email validation will reject non-string values #27735

Merged
merged 5 commits into from
Mar 4, 2019
Merged

[5.8] Email validation will reject non-string values #27735

merged 5 commits into from
Mar 4, 2019

Conversation

paul-thebaud
Copy link
Contributor

@paul-thebaud paul-thebaud commented Mar 1, 2019

In Laravel 5.7, giving a non-string value to a validator was returning a validation error, but in Laravel 5.8, it throw an ErrorException with "Array to string conversion".

This pull-request fix this by checking that the value to validate is a string (using is_string method) or an object which has the __toString method, before validating it using Egulias EmailValidator.

@@ -626,7 +626,7 @@ protected function extractDistinctValues($attribute)
*/
public function validateEmail($attribute, $value)
{
return (new EmailValidator)->isValid($value, new RFCValidation);
return is_string($value) && (new EmailValidator)->isValid($value, new RFCValidation);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFCValidation::isValid() also accepts an object implementing __toString():

https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/RFCValidation.php#L30

Copy link
Contributor Author

@paul-thebaud paul-thebaud Mar 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this. Now, the validation method will first check to have a string or an object implementing __toString, before validating it using RFC.

@paul-thebaud
Copy link
Contributor Author

Ok, thank you for the information.
I will update my pull-request to comply with this soon.

@GrahamCampbell GrahamCampbell changed the title Email validation will reject non-string values [5.8] Email validation will reject non-string values Mar 2, 2019
@taylorotwell taylorotwell merged commit d0a33d4 into laravel:5.8 Mar 4, 2019
taylorotwell pushed a commit to illuminate/validation that referenced this pull request Mar 4, 2019
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.

3 participants