mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-27 04:10:30 +08:00
fixed EmailValidator IDN and full pattern support
also made everything conistent with client validation
This commit is contained in:
@@ -117,16 +117,16 @@ yii.validation = (function ($) {
|
||||
var valid = true;
|
||||
|
||||
if (options.enableIDN) {
|
||||
var regexp = /^(.*)@(.*)$/,
|
||||
var regexp = /^(.*<?)(.*)@(.*)(>?)$/,
|
||||
matches = regexp.exec(value);
|
||||
if (matches === null) {
|
||||
valid = false;
|
||||
} else {
|
||||
value = punycode.toASCII(matches[1]) + '@' + punycode.toASCII(matches[2]);
|
||||
value = matches[1] + punycode.toASCII(matches[2]) + '@' + punycode.toASCII(matches[3]) + matches[4];
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid || !(value.match(options.pattern) && (!options.allowName || value.match(options.fullPattern)))) {
|
||||
if (!valid || !(value.match(options.pattern) || (options.allowName && value.match(options.fullPattern)))) {
|
||||
addMessage(messages, options.message, value);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -93,15 +93,15 @@ class EmailValidator extends Validator
|
||||
public function validateValue($value)
|
||||
{
|
||||
// make sure string length is limited to avoid DOS attacks
|
||||
if (!is_string($value) || strlen($value) >= 255) {
|
||||
if (!is_string($value) || strlen($value) >= 320) {
|
||||
return false;
|
||||
}
|
||||
if (($atPosition = strpos($value, '@')) === false) {
|
||||
if (!preg_match('/^(.*<?)(.*)@(.*)(>?)$/', $value, $matches)) {
|
||||
return false;
|
||||
}
|
||||
$domain = rtrim(substr($value, $atPosition + 1), '>');
|
||||
$domain = $matches[3];
|
||||
if ($this->enableIDN) {
|
||||
$value = idn_to_ascii(ltrim(substr($value, 0, $atPosition), '<')) . '@' . idn_to_ascii($domain);
|
||||
$value = $matches[1] . idn_to_ascii($matches[2]) . '@' . idn_to_ascii($domain) . $matches[4];
|
||||
}
|
||||
$valid = preg_match($this->pattern, $value) || $this->allowName && preg_match($this->fullPattern, $value);
|
||||
if ($valid) {
|
||||
|
||||
Reference in New Issue
Block a user