Updated validation regex from Michael Rushton
Update unit tests
This commit is contained in:
parent
a5ac40468b
commit
104869b669
|
|
@ -735,7 +735,7 @@ class PHPMailer {
|
|||
* @access public
|
||||
*/
|
||||
public static function ValidateAddress($address) {
|
||||
return (boolean)preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
|
||||
return (boolean)preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test email address validation
|
||||
* Test addresses obtained from http://isemail.info
|
||||
* Some failing cases commented out, mostly not significant though
|
||||
* Some failing cases commented out that are apparently up for debate!
|
||||
*/
|
||||
function testValidate()
|
||||
{
|
||||
|
|
@ -322,7 +322,7 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
|
|||
'"first\last"@iana.org',
|
||||
'first.last@[12.34.56.78]',
|
||||
'first.last@[IPv6:::12.34.56.78]',
|
||||
// 'first.last@[IPv6:1111:2222:3333::4444:12.34.56.78]',
|
||||
'first.last@[IPv6:1111:2222:3333::4444:12.34.56.78]',
|
||||
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78]',
|
||||
'first.last@[IPv6:::1111:2222:3333:4444:5555:6666]',
|
||||
'first.last@[IPv6:1111:2222:3333::4444:5555:6666]',
|
||||
|
|
@ -332,8 +332,8 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
|
|||
'first.last@3com.com',
|
||||
'first.last@123.iana.org',
|
||||
'"first\last"@iana.org',
|
||||
// 'first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78]',
|
||||
// 'first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777]',
|
||||
'first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78]',
|
||||
'first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777]',
|
||||
'first.last@example.123',
|
||||
'first.last@com',
|
||||
'"Abc\@def"@iana.org',
|
||||
|
|
@ -387,19 +387,19 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
|
|||
'"first.middle"."last"@iana.org',
|
||||
'"first.middle.last"@iana.org',
|
||||
'"first..last"@iana.org',
|
||||
// '"first\\\"last"@iana.org',
|
||||
'"first\"last"@iana.org',
|
||||
'first."mid\dle"."last"@iana.org',
|
||||
'"test blah"@iana.org',
|
||||
// '(foo)cal(bar)@(baz)iamcal.com(quux)',
|
||||
// 'cal@iamcal(woo).(yay)com',
|
||||
// 'cal(woo(yay)hoopla)@iamcal.com',
|
||||
// 'cal(foo\@bar)@iamcal.com',
|
||||
// 'cal(foo\)bar)@iamcal.com',
|
||||
// 'first().last@iana.org',
|
||||
// 'pete(his account)@silly.test(his host)',
|
||||
// 'c@(Chris\'s host.)public.example',
|
||||
// 'jdoe@machine(comment). example',
|
||||
// '1234 @ local(blah) .machine .example',
|
||||
'(foo)cal(bar)@(baz)iamcal.com(quux)',
|
||||
'cal@iamcal(woo).(yay)com',
|
||||
'cal(woo(yay)hoopla)@iamcal.com',
|
||||
'cal(foo\@bar)@iamcal.com',
|
||||
'cal(foo\)bar)@iamcal.com',
|
||||
'first().last@iana.org',
|
||||
'pete(his account)@silly.test(his host)',
|
||||
'c@(Chris\'s host.)public.example',
|
||||
'jdoe@machine(comment). example',
|
||||
'1234 @ local(blah) .machine .example',
|
||||
'first(abc.def).last@iana.org',
|
||||
'first(a"bc.def).last@iana.org',
|
||||
'first.(")middle.last(")@iana.org',
|
||||
|
|
@ -425,8 +425,8 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
|
|||
'user%uucp!path@berkeley.edu',
|
||||
'first.last @iana.org',
|
||||
'cdburgess+!#$%&\'*-/=?+_{}|~test@gmail.com',
|
||||
// 'first.last@[IPv6:::a2:a3:a4:b1:b2:b3:b4]',
|
||||
// 'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3::]',
|
||||
'first.last@[IPv6:::a2:a3:a4:b1:b2:b3:b4]',
|
||||
'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3::]',
|
||||
'first.last@[IPv6:::]',
|
||||
'first.last@[IPv6:::b4]',
|
||||
'first.last@[IPv6:::b3:b4]',
|
||||
|
|
@ -436,9 +436,9 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
|
|||
'first.last@[IPv6:0123:4567:89ab:cdef::]',
|
||||
'first.last@[IPv6:0123:4567:89ab:CDEF::]',
|
||||
'first.last@[IPv6:::a3:a4:b1:ffff:11.22.33.44]',
|
||||
// 'first.last@[IPv6:::a2:a3:a4:b1:ffff:11.22.33.44]',
|
||||
'first.last@[IPv6:::a2:a3:a4:b1:ffff:11.22.33.44]',
|
||||
'first.last@[IPv6:a1:a2:a3:a4::11.22.33.44]',
|
||||
// 'first.last@[IPv6:a1:a2:a3:a4:b1::11.22.33.44]',
|
||||
'first.last@[IPv6:a1:a2:a3:a4:b1::11.22.33.44]',
|
||||
'first.last@[IPv6:a1::11.22.33.44]',
|
||||
'first.last@[IPv6:a1:a2::11.22.33.44]',
|
||||
'first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.44]',
|
||||
|
|
@ -458,7 +458,7 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
|
|||
'first.last.@iana.org',
|
||||
'first..last@iana.org',
|
||||
'"first"last"@iana.org',
|
||||
// '"""@iana.org',
|
||||
'"""@iana.org',
|
||||
'"\"@iana.org',
|
||||
// '""@iana.org',
|
||||
'first\@last@iana.org',
|
||||
|
|
@ -551,8 +551,8 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
|
|||
'-@a..com',
|
||||
'invalid@about.museum-',
|
||||
'test@...........com',
|
||||
// '"Unicode NULL "@char.com',
|
||||
'Unicode NULL @char.com',
|
||||
'"Unicode NULL' . chr(0) . '"@char.com',
|
||||
'Unicode NULL' . chr(0) . '@char.com',
|
||||
'first.last@[IPv6::]',
|
||||
'first.last@[IPv6::::]',
|
||||
'first.last@[IPv6::b4]',
|
||||
|
|
|
|||
Loading…
Reference in New Issue