Skip to content

EmailValidator fails on valid email address (when IDN is enabled) and address contains .- #18585

@ihitbuttons

Description

@ihitbuttons

What steps will reproduce the problem?

Validate any (valid) email address with .- in the address, and set enableIDN to true.
i.e. user.-name@domain.com (this is a valid email address).

What is the expected result?

The email will validate.

What do you get instead?

The email fails validation.

Additional info

I traced this problem down. What happens is in framework/validators/EmailValidator.php, line 80
$matches['local'] = $this->idnToAscii($matches['local']);

The idnToAscii function returns false (because line 142 returns false). It seems that a string with .- in it will fail to convert to ascii in this function, causing valid email addresses to fail email validation.

This causes the email address to end up being (in the example above) @domain.com when re-assembled on line 81:
$value = $matches['name'] . $matches['open'] . $matches['local'] . '@' . $matches['domain'] . $matches['close'];

Q A
Yii version 2.0.41.1
PHP version 7.4.16
Operating system Linux

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions