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
8dab87be
Commit
8dab87be
authored
Nov 20, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed EmailValidator IDN and full pattern support
also made everything conistent with client validation
parent
64862f96
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
7 deletions
+56
-7
yii.validation.js
framework/yii/assets/yii.validation.js
+3
-3
EmailValidator.php
framework/yii/validators/EmailValidator.php
+4
-4
EmailValidatorTest.php
tests/unit/framework/validators/EmailValidatorTest.php
+49
-0
No files found.
framework/yii/assets/yii.validation.js
View file @
8dab87be
...
...
@@ -117,16 +117,16 @@ yii.validation = (function ($) {
var
valid
=
true
;
if
(
options
.
enableIDN
)
{
var
regexp
=
/^
(
.*
)
@
(
.*
)
$/
,
var
regexp
=
/^
(
.*
<
?)(
.*
)
@
(
.*
)(
>
?
)
$/
,
matches
=
regexp
.
exec
(
value
);
if
(
matches
===
null
)
{
valid
=
false
;
}
else
{
value
=
punycode
.
toASCII
(
matches
[
1
])
+
'@'
+
punycode
.
toASCII
(
matches
[
2
])
;
value
=
matches
[
1
]
+
punycode
.
toASCII
(
matches
[
2
])
+
'@'
+
punycode
.
toASCII
(
matches
[
3
])
+
matches
[
4
]
;
}
}
if
(
!
valid
||
!
(
value
.
match
(
options
.
pattern
)
&&
(
!
options
.
allowName
||
value
.
match
(
options
.
fullPattern
))))
{
if
(
!
valid
||
!
(
value
.
match
(
options
.
pattern
)
||
(
options
.
allowName
&&
value
.
match
(
options
.
fullPattern
))))
{
addMessage
(
messages
,
options
.
message
,
value
);
}
},
...
...
framework/yii/validators/EmailValidator.php
View file @
8dab87be
...
...
@@ -93,15 +93,15 @@ class EmailValidator extends Validator
public
function
validateValue
(
$value
)
{
// make sure string length is limited to avoid DOS attacks
if
(
!
is_string
(
$value
)
||
strlen
(
$value
)
>=
255
)
{
if
(
!
is_string
(
$value
)
||
strlen
(
$value
)
>=
320
)
{
return
false
;
}
if
(
(
$atPosition
=
strpos
(
$value
,
'@'
))
===
false
)
{
if
(
!
preg_match
(
'/^(.*<?)(.*)@(.*)(>?)$/'
,
$value
,
$matches
)
)
{
return
false
;
}
$domain
=
rtrim
(
substr
(
$value
,
$atPosition
+
1
),
'>'
)
;
$domain
=
$matches
[
3
]
;
if
(
$this
->
enableIDN
)
{
$value
=
idn_to_ascii
(
ltrim
(
substr
(
$value
,
0
,
$atPosition
),
'<'
))
.
'@'
.
idn_to_ascii
(
$domain
)
;
$value
=
$matches
[
1
]
.
idn_to_ascii
(
$matches
[
2
])
.
'@'
.
idn_to_ascii
(
$domain
)
.
$matches
[
4
]
;
}
$valid
=
preg_match
(
$this
->
pattern
,
$value
)
||
$this
->
allowName
&&
preg_match
(
$this
->
fullPattern
,
$value
);
if
(
$valid
)
{
...
...
tests/unit/framework/validators/EmailValidatorTest.php
View file @
8dab87be
...
...
@@ -24,6 +24,55 @@ class EmailValidatorTest extends TestCase
$this
->
assertTrue
(
$validator
->
validateValue
(
'sam@rmcreative.ru'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'5011@gmail.com'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'rmcreative.ru'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'Carsten Brandt <mail@cebe.cc>'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'"Carsten Brandt" <mail@cebe.cc>'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'<mail@cebe.cc>'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'info@örtliches.de'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'sam@рмкреатиф.ru'
));
$validator
->
allowName
=
true
;
$this
->
assertTrue
(
$validator
->
validateValue
(
'sam@rmcreative.ru'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'5011@gmail.com'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'rmcreative.ru'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'Carsten Brandt <mail@cebe.cc>'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'"Carsten Brandt" <mail@cebe.cc>'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'<mail@cebe.cc>'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'info@örtliches.de'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'sam@рмкреатиф.ru'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'Informtation info@oertliches.de'
));
}
public
function
testValidateIdnValue
()
{
if
(
!
extension_loaded
(
"intl"
))
{
$this
->
markTestSkipped
(
"intl not installed. Skipping."
);
}
$validator
=
new
EmailValidator
();
$validator
->
enableIDN
=
true
;
$this
->
assertTrue
(
$validator
->
validateValue
(
'info@örtliches.de'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'sam@рмкреатиф.ru'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'sam@rmcreative.ru'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'5011@gmail.com'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'rmcreative.ru'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'Carsten Brandt <mail@cebe.cc>'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'"Carsten Brandt" <mail@cebe.cc>'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'<mail@cebe.cc>'
));
$validator
->
allowName
=
true
;
$this
->
assertTrue
(
$validator
->
validateValue
(
'info@örtliches.de'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'Informtation <info@örtliches.de>'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'Informtation info@örtliches.de'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'sam@рмкреатиф.ru'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'sam@rmcreative.ru'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'5011@gmail.com'
));
$this
->
assertFalse
(
$validator
->
validateValue
(
'rmcreative.ru'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'Carsten Brandt <mail@cebe.cc>'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'"Carsten Brandt" <mail@cebe.cc>'
));
$this
->
assertTrue
(
$validator
->
validateValue
(
'<mail@cebe.cc>'
));
}
public
function
testValidateValueMx
()
...
...
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