Browse Source

UrlValidator and EmailValidator IDN support fixes.

tags/2.0.0-beta
resurtm 12 years ago
parent
commit
6458b8df8f
  1. 10
      yii/assets/yii.validation.js
  2. 6
      yii/validators/EmailValidator.php
  3. 6
      yii/validators/UrlValidator.php
  4. 2
      yii/widgets/ActiveField.php

10
yii/assets/yii.validation.js

@ -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 {

6
yii/validators/EmailValidator.php

@ -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;

6
yii/validators/UrlValidator.php

@ -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;

2
yii/widgets/ActiveField.php

@ -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;
}

Loading…
Cancel
Save