mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-13 04:38:03 +08:00
UrlValidator and EmailValidator IDN support fixes.
This commit is contained in:
@@ -112,8 +112,9 @@ yii.validation = (function ($) {
|
||||
|
||||
var valid = true;
|
||||
|
||||
if (options.idn) {
|
||||
var regexp = /^(.*)@(.*)$/, matches = regexp.exec(value);
|
||||
if (options.enableIDN) {
|
||||
var regexp = /^(.*)@(.*)$/,
|
||||
matches = regexp.exec(value);
|
||||
if (matches === null) {
|
||||
valid = false;
|
||||
} else {
|
||||
@@ -137,8 +138,9 @@ yii.validation = (function ($) {
|
||||
|
||||
var valid = true;
|
||||
|
||||
if (options.idn) {
|
||||
var regexp = /^([^:]+):\/\/([^\/]+)(.*)?/, matches = regexp.exec(value);
|
||||
if (options.enableIDN) {
|
||||
var regexp = /^([^:]+):\/\/([^\/]+)(.*)?/,
|
||||
matches = regexp.exec(value);
|
||||
if (matches === null) {
|
||||
valid = false;
|
||||
} else {
|
||||
|
||||
@@ -51,7 +51,7 @@ class EmailValidator extends Validator
|
||||
* @var boolean whether validation process should take into account IDN (internationalized domain
|
||||
* names). Defaults to false meaning that validation of emails containing IDN will always fail.
|
||||
*/
|
||||
public $idn = false;
|
||||
public $enableIDN = false;
|
||||
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ class EmailValidator extends Validator
|
||||
return false;
|
||||
}
|
||||
$domain = rtrim(substr($value, $atPosition + 1), '>');
|
||||
if ($this->idn) {
|
||||
if ($this->enableIDN) {
|
||||
$value = idn_to_ascii(ltrim(substr($value, 0, $atPosition), '<')) . '@' . idn_to_ascii($domain);
|
||||
}
|
||||
$valid = preg_match($this->pattern, $value) || $this->allowName && preg_match($this->fullPattern, $value);
|
||||
@@ -125,7 +125,7 @@ class EmailValidator extends Validator
|
||||
'{attribute}' => $object->getAttributeLabel($attribute),
|
||||
'{value}' => $object->$attribute,
|
||||
))),
|
||||
'idn' => (boolean)$this->idn,
|
||||
'enableIDN' => (boolean)$this->enableIDN,
|
||||
);
|
||||
if ($this->skipOnEmpty) {
|
||||
$options['skipOnEmpty'] = 1;
|
||||
|
||||
@@ -42,7 +42,7 @@ class UrlValidator extends Validator
|
||||
* domain names). Defaults to false meaning that validation of URLs containing IDN will always
|
||||
* fail.
|
||||
*/
|
||||
public $idn = false;
|
||||
public $enableIDN = false;
|
||||
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ class UrlValidator extends Validator
|
||||
$pattern = $this->pattern;
|
||||
}
|
||||
|
||||
if ($this->idn) {
|
||||
if ($this->enableIDN) {
|
||||
$value = preg_replace_callback('/:\/\/([^\/]+)/', function($matches) {
|
||||
return '://' . idn_to_ascii($matches[1]);
|
||||
}, $value);
|
||||
@@ -127,7 +127,7 @@ class UrlValidator extends Validator
|
||||
'{attribute}' => $object->getAttributeLabel($attribute),
|
||||
'{value}' => $object->$attribute,
|
||||
))),
|
||||
'idn' => (boolean)$this->idn,
|
||||
'enableIDN' => (boolean)$this->enableIDN,
|
||||
);
|
||||
if ($this->skipOnEmpty) {
|
||||
$options['skipOnEmpty'] = 1;
|
||||
|
||||
@@ -124,7 +124,7 @@ class ActiveField extends Component
|
||||
$options['class'] = implode(' ', $class);
|
||||
|
||||
foreach ($this->model->getActiveValidators($attribute) as $validator) {
|
||||
if (($validator instanceof EmailValidator || $validator instanceof UrlValidator) && $validator->idn) {
|
||||
if (($validator instanceof EmailValidator || $validator instanceof UrlValidator) && $validator->enableIDN) {
|
||||
$this->form->view->registerAssetBundle('punycode');
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user