Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
6458b8df
Commit
6458b8df
authored
May 15, 2013
by
resurtm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UrlValidator and EmailValidator IDN support fixes.
parent
8a5e1f4f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
11 deletions
+13
-11
yii.validation.js
yii/assets/yii.validation.js
+6
-4
EmailValidator.php
yii/validators/EmailValidator.php
+3
-3
UrlValidator.php
yii/validators/UrlValidator.php
+3
-3
ActiveField.php
yii/widgets/ActiveField.php
+1
-1
No files found.
yii/assets/yii.validation.js
View file @
6458b8df
...
...
@@ -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
{
...
...
yii/validators/EmailValidator.php
View file @
6458b8df
...
...
@@ -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
;
...
...
yii/validators/UrlValidator.php
View file @
6458b8df
...
...
@@ -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
;
...
...
yii/widgets/ActiveField.php
View file @
6458b8df
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment