mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Refactoring method per request
This commit is contained in:
@ -77,21 +77,7 @@ class EmailValidator extends Validator
|
|||||||
$valid = false;
|
$valid = false;
|
||||||
} else {
|
} else {
|
||||||
if ($this->enableIDN) {
|
if ($this->enableIDN) {
|
||||||
// https://github.com/yiisoft/yii2/issues/18585
|
$matches['local'] = $this->validateIdnValue($matches['local']);
|
||||||
$localIDNTest = $this->idnToAscii($matches['local']);
|
|
||||||
|
|
||||||
if ($localIDNTest === false) {
|
|
||||||
$newPatternExploded = explode('@', $this->pattern);
|
|
||||||
$newPattern = $newPatternExploded[0] . "$/";
|
|
||||||
$newFullPatternExploded = explode('@', $this->fullPattern);
|
|
||||||
$newFullPattern = $newFullPatternExploded[0] . '@' . $newFullPatternExploded[1] ."$/";
|
|
||||||
if (!preg_match($newPattern, $matches['local']) || ($this->allowName && preg_match($newFullPattern, $matches['local']))) {
|
|
||||||
$matches['local'] = $localIDNTest;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$matches['local'] = $localIDNTest;
|
|
||||||
}
|
|
||||||
|
|
||||||
$matches['domain'] = $this->idnToAscii($matches['domain']);
|
$matches['domain'] = $this->idnToAscii($matches['domain']);
|
||||||
$value = $matches['name'] . $matches['open'] . $matches['local'] . '@' . $matches['domain'] . $matches['close'];
|
$value = $matches['name'] . $matches['open'] . $matches['local'] . '@' . $matches['domain'] . $matches['close'];
|
||||||
}
|
}
|
||||||
@ -190,4 +176,28 @@ class EmailValidator extends Validator
|
|||||||
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
* @return string|bool returns string if it is valid and/or can be converted, bool false if it can't be converted and/or is invalid
|
||||||
|
* @see https://github.com/yiisoft/yii2/issues/18585
|
||||||
|
*/
|
||||||
|
private function validateIdnValue ($value)
|
||||||
|
{
|
||||||
|
$idnTest = $this->idnToAscii($value);
|
||||||
|
|
||||||
|
if ($idnTest === false) {
|
||||||
|
$newPatternExploded = explode('@', $this->pattern);
|
||||||
|
$newPattern = $newPatternExploded[0] . "$/";
|
||||||
|
|
||||||
|
$newFullPatternExploded = explode('@', $this->fullPattern);
|
||||||
|
$newFullPattern = $newFullPatternExploded[0] . '@' . $newFullPatternExploded[1] ."$/";
|
||||||
|
|
||||||
|
if (preg_match($newPattern, $value) || ($this->allowName && preg_match($newFullPattern, $value))) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $idnTest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user