Commit 6458b8df by resurtm

UrlValidator and EmailValidator IDN support fixes.

parent 8a5e1f4f
...@@ -112,8 +112,9 @@ yii.validation = (function ($) { ...@@ -112,8 +112,9 @@ yii.validation = (function ($) {
var valid = true; var valid = true;
if (options.idn) { if (options.enableIDN) {
var regexp = /^(.*)@(.*)$/, matches = regexp.exec(value); var regexp = /^(.*)@(.*)$/,
matches = regexp.exec(value);
if (matches === null) { if (matches === null) {
valid = false; valid = false;
} else { } else {
...@@ -137,8 +138,9 @@ yii.validation = (function ($) { ...@@ -137,8 +138,9 @@ yii.validation = (function ($) {
var valid = true; var valid = true;
if (options.idn) { if (options.enableIDN) {
var regexp = /^([^:]+):\/\/([^\/]+)(.*)?/, matches = regexp.exec(value); var regexp = /^([^:]+):\/\/([^\/]+)(.*)?/,
matches = regexp.exec(value);
if (matches === null) { if (matches === null) {
valid = false; valid = false;
} else { } else {
......
...@@ -51,7 +51,7 @@ class EmailValidator extends Validator ...@@ -51,7 +51,7 @@ class EmailValidator extends Validator
* @var boolean whether validation process should take into account IDN (internationalized domain * @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. * 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 ...@@ -94,7 +94,7 @@ class EmailValidator extends Validator
return false; return false;
} }
$domain = rtrim(substr($value, $atPosition + 1), '>'); $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); $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); $valid = preg_match($this->pattern, $value) || $this->allowName && preg_match($this->fullPattern, $value);
...@@ -125,7 +125,7 @@ class EmailValidator extends Validator ...@@ -125,7 +125,7 @@ class EmailValidator extends Validator
'{attribute}' => $object->getAttributeLabel($attribute), '{attribute}' => $object->getAttributeLabel($attribute),
'{value}' => $object->$attribute, '{value}' => $object->$attribute,
))), ))),
'idn' => (boolean)$this->idn, 'enableIDN' => (boolean)$this->enableIDN,
); );
if ($this->skipOnEmpty) { if ($this->skipOnEmpty) {
$options['skipOnEmpty'] = 1; $options['skipOnEmpty'] = 1;
......
...@@ -42,7 +42,7 @@ class UrlValidator extends Validator ...@@ -42,7 +42,7 @@ class UrlValidator extends Validator
* domain names). Defaults to false meaning that validation of URLs containing IDN will always * domain names). Defaults to false meaning that validation of URLs containing IDN will always
* fail. * fail.
*/ */
public $idn = false; public $enableIDN = false;
/** /**
...@@ -93,7 +93,7 @@ class UrlValidator extends Validator ...@@ -93,7 +93,7 @@ class UrlValidator extends Validator
$pattern = $this->pattern; $pattern = $this->pattern;
} }
if ($this->idn) { if ($this->enableIDN) {
$value = preg_replace_callback('/:\/\/([^\/]+)/', function($matches) { $value = preg_replace_callback('/:\/\/([^\/]+)/', function($matches) {
return '://' . idn_to_ascii($matches[1]); return '://' . idn_to_ascii($matches[1]);
}, $value); }, $value);
...@@ -127,7 +127,7 @@ class UrlValidator extends Validator ...@@ -127,7 +127,7 @@ class UrlValidator extends Validator
'{attribute}' => $object->getAttributeLabel($attribute), '{attribute}' => $object->getAttributeLabel($attribute),
'{value}' => $object->$attribute, '{value}' => $object->$attribute,
))), ))),
'idn' => (boolean)$this->idn, 'enableIDN' => (boolean)$this->enableIDN,
); );
if ($this->skipOnEmpty) { if ($this->skipOnEmpty) {
$options['skipOnEmpty'] = 1; $options['skipOnEmpty'] = 1;
......
...@@ -124,7 +124,7 @@ class ActiveField extends Component ...@@ -124,7 +124,7 @@ class ActiveField extends Component
$options['class'] = implode(' ', $class); $options['class'] = implode(' ', $class);
foreach ($this->model->getActiveValidators($attribute) as $validator) { 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'); $this->form->view->registerAssetBundle('punycode');
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment