Skip to content

Email validator is not validating domain part #29433

Closed
@Gegirhasut

Description

@Gegirhasut
  • Laravel Version: 5.8
  • PHP Version: 7.2
  • Database Driver & Version:

Description:

Email validator in Laravel 5.8 accept email with wrong domain part.

Steps To Reproduce:

  1. Install Laravel 5.8
  2. Add base authorization. You will have in RegisterController next function:
protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:6', 'confirmed'],
        ]);
    }
  1. Try to Register with email "sadada@fsfdsfsdfds"- the domain part is not full.
  2. Validator will accept email.

Laravel 5.7 is working fine.
Let's check the code in 5.7 and 5.8, file ValidatesAttributes.php

Laravel 5.7 (working, standard php function):

public function validateEmail($attribute, $value)
{
    return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
}

Laravel 5.8 (not working, something custom now):

public function validateEmail($attribute, $value)
{
    if (! is_string($value) && ! (is_object($value) && method_exists($value, '__toString'))) {
        return false;
    }

    return (new EmailValidator)->isValid($value, new RFCValidation);
}

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