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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
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
Show 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 ($) {
...
@@ -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
{
...
...
yii/validators/EmailValidator.php
View file @
6458b8df
...
@@ -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
;
...
...
yii/validators/UrlValidator.php
View file @
6458b8df
...
@@ -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
;
...
...
yii/widgets/ActiveField.php
View file @
6458b8df
...
@@ -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
;
}
}
...
...
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