Skip to content

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.

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