Update to drupal-org-drupal 8.0.0-rc2. For more information, see https://www.drupal.org/node/2598668
This commit is contained in:
parent
f32e58e4b1
commit
8e18df8c36
3062 changed files with 15044 additions and 172506 deletions
|
@ -1,69 +0,0 @@
|
|||
Email length
|
||||
------------
|
||||
http://tools.ietf.org/html/rfc5321#section-4.1.2
|
||||
Forward-path = Path
|
||||
|
||||
Path = "<" [ A-d-l ":" ] Mailbox ">"
|
||||
|
||||
http://tools.ietf.org/html/rfc5321#section-4.5.3.1.3
|
||||
http://tools.ietf.org/html/rfc1035#section-2.3.4
|
||||
|
||||
DNS
|
||||
---
|
||||
|
||||
http://tools.ietf.org/html/rfc5321#section-2.3.5
|
||||
Names that can
|
||||
be resolved to MX RRs or address (i.e., A or AAAA) RRs (as discussed
|
||||
in Section 5) are permitted, as are CNAME RRs whose targets can be
|
||||
resolved, in turn, to MX or address RRs.
|
||||
|
||||
http://tools.ietf.org/html/rfc5321#section-5.1
|
||||
The lookup first attempts to locate an MX record associated with the
|
||||
name. If a CNAME record is found, the resulting name is processed as
|
||||
if it were the initial name. ... If an empty list of MXs is returned,
|
||||
the address is treated as if it was associated with an implicit MX
|
||||
RR, with a preference of 0, pointing to that host.
|
||||
|
||||
is_email() author's note: We will regard the existence of a CNAME to be
|
||||
sufficient evidence of the domain's existence. For performance reasons
|
||||
we will not repeat the DNS lookup for the CNAME's target, but we will
|
||||
raise a warning because we didn't immediately find an MX record.
|
||||
|
||||
Check for TLD addresses
|
||||
-----------------------
|
||||
TLD addresses are specifically allowed in RFC 5321 but they are
|
||||
unusual to say the least. We will allocate a separate
|
||||
status to these addresses on the basis that they are more likely
|
||||
to be typos than genuine addresses (unless we've already
|
||||
established that the domain does have an MX record)
|
||||
|
||||
http://tools.ietf.org/html/rfc5321#section-2.3.5
|
||||
In the case
|
||||
of a top-level domain used by itself in an email address, a single
|
||||
string is used without any dots. This makes the requirement,
|
||||
described in more detail below, that only fully-qualified domain
|
||||
names appear in SMTP transactions on the public Internet,
|
||||
particularly important where top-level domains are involved.
|
||||
|
||||
TLD format
|
||||
----------
|
||||
The format of TLDs has changed a number of times. The standards
|
||||
used by IANA have been largely ignored by ICANN, leading to
|
||||
confusion over the standards being followed. These are not defined
|
||||
anywhere, except as a general component of a DNS host name (a label).
|
||||
However, this could potentially lead to 123.123.123.123 being a
|
||||
valid DNS name (rather than an IP address) and thereby creating
|
||||
an ambiguity. The most authoritative statement on TLD formats that
|
||||
the author can find is in a (rejected!) erratum to RFC 1123
|
||||
submitted by John Klensin, the author of RFC 5321:
|
||||
|
||||
http://www.rfc-editor.org/errata_search.php?rfc=1123&eid=1353
|
||||
However, a valid host name can never have the dotted-decimal
|
||||
form #.#.#.#, since this change does not permit the highest-level
|
||||
component label to start with a digit even if it is not all-numeric.
|
||||
|
||||
Comments
|
||||
--------
|
||||
Comments at the start of the domain are deprecated in the text
|
||||
Comments at the start of a subdomain are obs-domain
|
||||
(http://tools.ietf.org/html/rfc5322#section-3.4.1)
|
|
@ -1,89 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
||||
<title>The BNF from RFC 5321 defining parts of a valid SMTP address</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<pre style="font-size:11px;">
|
||||
Mailbox = Local-part "@" ( Domain / address-literal )
|
||||
|
||||
Local-part = Dot-string / Quoted-string
|
||||
; MAY be case-sensitive
|
||||
|
||||
|
||||
Dot-string = Atom *("." Atom)
|
||||
|
||||
Atom = 1*atext
|
||||
|
||||
Quoted-string = DQUOTE *QcontentSMTP DQUOTE
|
||||
|
||||
QcontentSMTP = qtextSMTP / quoted-pairSMTP
|
||||
|
||||
quoted-pairSMTP = %d92 %d32-126
|
||||
; i.e., backslash followed by any ASCII
|
||||
; graphic (including itself) or SPace
|
||||
|
||||
qtextSMTP = %d32-33 / %d35-91 / %d93-126
|
||||
; i.e., within a quoted string, any
|
||||
; ASCII graphic or space is permitted
|
||||
; without blackslash-quoting except
|
||||
; double-quote and the backslash itself.
|
||||
|
||||
Domain = sub-domain *("." sub-domain)
|
||||
|
||||
sub-domain = Let-dig [Ldh-str]
|
||||
|
||||
Let-dig = ALPHA / DIGIT
|
||||
|
||||
Ldh-str = *( ALPHA / DIGIT / "-" ) Let-dig
|
||||
|
||||
address-literal = "[" ( IPv4-address-literal /
|
||||
IPv6-address-literal /
|
||||
General-address-literal ) "]"
|
||||
; See Section 4.1.3
|
||||
|
||||
IPv4-address-literal = Snum 3("." Snum)
|
||||
|
||||
IPv6-address-literal = "IPv6:" IPv6-addr
|
||||
|
||||
General-address-literal = Standardized-tag ":" 1*dcontent
|
||||
|
||||
Standardized-tag = Ldh-str
|
||||
; Standardized-tag MUST be specified in a
|
||||
; Standards-Track RFC and registered with IANA
|
||||
|
||||
dcontent = %d33-90 / ; Printable US-ASCII
|
||||
%d94-126 ; excl. "[", "\", "]"
|
||||
|
||||
Snum = 1*3DIGIT
|
||||
; representing a decimal integer
|
||||
; value in the range 0 through 255
|
||||
|
||||
IPv6-addr = IPv6-full / IPv6-comp / IPv6v4-full / IPv6v4-comp
|
||||
|
||||
IPv6-hex = 1*4HEXDIG
|
||||
|
||||
IPv6-full = IPv6-hex 7(":" IPv6-hex)
|
||||
|
||||
IPv6-comp = [IPv6-hex *5(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *5(":" IPv6-hex)]
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 6 groups in addition to the
|
||||
; "::" may be present.
|
||||
|
||||
IPv6v4-full = IPv6-hex 5(":" IPv6-hex) ":" IPv4-address-literal
|
||||
|
||||
IPv6v4-comp = [IPv6-hex *3(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *3(":" IPv6-hex) ":"]
|
||||
IPv4-address-literal
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 4 groups in addition to the
|
||||
; "::" and IPv4-address-literal may be present.
|
||||
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,141 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
||||
<title>The BNF from RFC 5322 defining parts of a valid internet message address</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<pre style="font-size:11px;">
|
||||
addr-spec = local-part "@" domain
|
||||
|
||||
local-part = dot-atom / quoted-string / obs-local-part
|
||||
|
||||
dot-atom = [CFWS] dot-atom-text [CFWS]
|
||||
|
||||
CFWS = (1*([FWS] comment) [FWS]) / FWS
|
||||
|
||||
FWS = ([*WSP CRLF] 1*WSP) / obs-FWS
|
||||
; Folding white space
|
||||
|
||||
WSP = SP / HTAB ; white space
|
||||
|
||||
obs-FWS = 1*([CRLF] WSP) ; As amended in erratum #1908
|
||||
|
||||
ctext = %d33-39 / ; Printable US-ASCII
|
||||
%d42-91 / ; characters not including
|
||||
%d93-126 / ; "(", ")", or "\"
|
||||
obs-ctext
|
||||
|
||||
obs-ctext = obs-NO-WS-CTL
|
||||
ccontent = ctext / quoted-pair / comment
|
||||
|
||||
comment = "(" *([FWS] ccontent) [FWS] ")"
|
||||
|
||||
dot-atom-text = 1*atext *("." 1*atext)
|
||||
|
||||
atext = ALPHA / DIGIT / ; Printable US-ASCII
|
||||
"!" / "#" / ; characters not including
|
||||
"$" / "%" / ; specials. Used for atoms.
|
||||
"&" / "'" /
|
||||
"*" / "+" /
|
||||
"-" / "/" /
|
||||
"=" / "?" /
|
||||
"^" / "_" /
|
||||
"`" / "{" /
|
||||
"|" / "}" /
|
||||
"~"
|
||||
|
||||
specials = "(" / ")" / ; Special characters that do
|
||||
"<" / ">" / ; not appear in atext
|
||||
"[" / "]" /
|
||||
":" / ";" /
|
||||
"@" / "\" /
|
||||
"," / "." /
|
||||
DQUOTE
|
||||
|
||||
quoted-string = [CFWS]
|
||||
DQUOTE *([FWS] qcontent) [FWS] DQUOTE
|
||||
[CFWS]
|
||||
|
||||
qcontent = qtext / quoted-pair
|
||||
|
||||
qtext = %d33 / ; Printable US-ASCII
|
||||
%d35-91 / ; characters not including
|
||||
%d93-126 / ; "\" or the quote character
|
||||
obs-qtext
|
||||
|
||||
obs-qtext = obs-NO-WS-CTL
|
||||
|
||||
obs-NO-WS-CTL = %d1-8 / ; US-ASCII control
|
||||
%d11 / ; characters that do not
|
||||
%d12 / ; include the carriage
|
||||
%d14-31 / ; return, line feed, and
|
||||
%d127 ; white space characters
|
||||
|
||||
quoted-pair = ("\" (VCHAR / WSP)) / obs-qp
|
||||
|
||||
VCHAR = %x21-7E ; visible (printing) characters
|
||||
|
||||
obs-qp = "\" (%d0 / obs-NO-WS-CTL / LF / CR)
|
||||
|
||||
obs-local-part = word *("." word)
|
||||
|
||||
word = atom / quoted-string
|
||||
|
||||
atom = [CFWS] 1*atext [CFWS]
|
||||
|
||||
domain = dot-atom / domain-literal / obs-domain
|
||||
|
||||
domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
|
||||
|
||||
dtext = %d33-90 / ; Printable US-ASCII
|
||||
%d94-126 / ; characters not including
|
||||
obs-dtext ; "[", "]", or "\"
|
||||
|
||||
obs-dtext = obs-NO-WS-CTL / quoted-pair
|
||||
|
||||
obs-domain = atom *("." atom)
|
||||
|
||||
NB For SMTP mail, the domain-literal is restricted by RFC5321 as follows:
|
||||
|
||||
Mailbox = Local-part "@" ( Domain / address-literal )
|
||||
|
||||
address-literal = "[" ( IPv4-address-literal /
|
||||
IPv6-address-literal /
|
||||
General-address-literal ) "]"
|
||||
|
||||
IPv4-address-literal = Snum 3("." Snum)
|
||||
|
||||
IPv6-address-literal = "IPv6:" IPv6-addr
|
||||
|
||||
Snum = 1*3DIGIT
|
||||
; representing a decimal integer
|
||||
; value in the range 0 through 255
|
||||
|
||||
IPv6-addr = IPv6-full / IPv6-comp / IPv6v4-full / IPv6v4-comp
|
||||
|
||||
IPv6-hex = 1*4HEXDIG
|
||||
|
||||
IPv6-full = IPv6-hex 7(":" IPv6-hex)
|
||||
|
||||
IPv6-comp = [IPv6-hex *5(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *5(":" IPv6-hex)]
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 6 groups in addition to the
|
||||
; "::" may be present.
|
||||
|
||||
IPv6v4-full = IPv6-hex 5(":" IPv6-hex) ":" IPv4-address-literal
|
||||
|
||||
IPv6v4-comp = [IPv6-hex *3(":" IPv6-hex)] "::"
|
||||
[IPv6-hex *3(":" IPv6-hex) ":"]
|
||||
IPv4-address-literal
|
||||
; The "::" represents at least 2 16-bit groups of
|
||||
; zeros. No more than 4 groups in addition to the
|
||||
; "::" and IPv4-address-literal may be present.
|
||||
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
if ( ! is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) {
|
||||
echo 'Could not find "vendor/autoload.php". Did you forget to run "composer install --dev"?'.PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require_once $autoloadFile;
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
require __DIR__ . '/../../bootstrap.php';
|
||||
|
||||
$iterations = 10000;
|
||||
|
||||
$testingMail = 'fabien@symfony.com';
|
||||
echo 'Testing ' . $iterations . ' iterations with ' . $testingMail . PHP_EOL;
|
||||
|
||||
$a = microtime(true);
|
||||
for ($i = 0; $i < $iterations; $i++) {
|
||||
$isValid = filter_var($testingMail, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
$b = microtime(true);
|
||||
echo ($b - $a) . ' seconds with filter_var' . PHP_EOL;
|
||||
|
||||
$a = microtime(true);
|
||||
for ($i = 0; $i < $iterations; $i++) {
|
||||
$validator = new EmailValidator();
|
||||
$isValid = $validator->isValid($testingMail);
|
||||
}
|
||||
$b = microtime(true);
|
||||
echo ($b - $a) . ' seconds with EmailValidator + instantiation' . PHP_EOL;
|
||||
|
||||
$a = microtime(true);
|
||||
$validator = new EmailValidator();
|
||||
for ($i = 0; $i < $iterations; $i++) {
|
||||
$isValid = $validator->isValid($testingMail);
|
||||
}
|
||||
$b = microtime(true);
|
||||
echo ($b - $a) . ' seconds with EmailValidator once instanced' . PHP_EOL;
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
require __DIR__ . '/../../bootstrap.php';
|
||||
require __DIR__ . '/../../../../isemail/is_email.php';
|
||||
|
||||
$iterations = 10000;
|
||||
|
||||
$testingMail = 'fabien@symfony.com';
|
||||
echo 'Testing ' . $iterations . ' iterations with ' . $testingMail . PHP_EOL;
|
||||
|
||||
$a = microtime(true);
|
||||
for ($i = 0; $i < $iterations; $i++) {
|
||||
$isValid = is_email($testingMail);
|
||||
}
|
||||
$b = microtime(true);
|
||||
echo ($b - $a) . ' seconds with is_email' . PHP_EOL;
|
||||
|
||||
$a = microtime(true);
|
||||
for ($i = 0; $i < $iterations; $i++) {
|
||||
$validator = new EmailValidator();
|
||||
$isValid = $validator->isValid($testingMail);
|
||||
}
|
||||
$b = microtime(true);
|
||||
echo ($b - $a) . ' seconds with EmailValidator + instantiation' . PHP_EOL;
|
||||
|
||||
$a = microtime(true);
|
||||
$validator = new EmailValidator();
|
||||
for ($i = 0; $i < $iterations; $i++) {
|
||||
$isValid = $validator->isValid($testingMail);
|
||||
}
|
||||
$b = microtime(true);
|
||||
echo ($b - $a) . ' seconds with EmailValidator once instanced' . PHP_EOL;
|
|
@ -1,161 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Tests;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
|
||||
class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testLexerExtendsLib()
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$this->assertInstanceOf('Doctrine\Common\Lexer\AbstractLexer', $lexer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTokens
|
||||
*
|
||||
*/
|
||||
public function testLexerTokens($str, $token)
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$lexer->setInput($str);
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals($token, $lexer->token['type']);
|
||||
}
|
||||
|
||||
public function testLexerParsesMultipleSpaces()
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$lexer->setInput(' ');
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::S_SP, $lexer->token['type']);
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::S_SP, $lexer->token['type']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidUTF8CharsProvider
|
||||
*/
|
||||
public function testLexerParsesInvalidUTF8($char)
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$lexer->setInput($char);
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
|
||||
$this->assertEquals(EmailLexer::INVALID, $lexer->token['type']);
|
||||
}
|
||||
|
||||
public function invalidUTF8CharsProvider()
|
||||
{
|
||||
$chars = array();
|
||||
for ($i = 0; $i < 0x100; ++$i) {
|
||||
$c = $this->utf8Chr($i);
|
||||
if (preg_match('/(?=\p{Cc})(?=[^\t\n\n\r])/u', $c) && !preg_match('/\x{0000}/u', $c)) {
|
||||
$chars[] = array($c);
|
||||
}
|
||||
}
|
||||
|
||||
return $chars;
|
||||
}
|
||||
|
||||
protected function utf8Chr($code_point)
|
||||
{
|
||||
|
||||
if ($code_point < 0 || 0x10FFFF < $code_point || (0xD800 <= $code_point && $code_point <= 0xDFFF)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($code_point < 0x80) {
|
||||
$hex[0] = $code_point;
|
||||
$ret = chr($hex[0]);
|
||||
} elseif ($code_point < 0x800) {
|
||||
$hex[0] = 0x1C0 | $code_point >> 6;
|
||||
$hex[1] = 0x80 | $code_point & 0x3F;
|
||||
$ret = chr($hex[0]).chr($hex[1]);
|
||||
} elseif ($code_point < 0x10000) {
|
||||
$hex[0] = 0xE0 | $code_point >> 12;
|
||||
$hex[1] = 0x80 | $code_point >> 6 & 0x3F;
|
||||
$hex[2] = 0x80 | $code_point & 0x3F;
|
||||
$ret = chr($hex[0]).chr($hex[1]).chr($hex[2]);
|
||||
} else {
|
||||
$hex[0] = 0xF0 | $code_point >> 18;
|
||||
$hex[1] = 0x80 | $code_point >> 12 & 0x3F;
|
||||
$hex[2] = 0x80 | $code_point >> 6 & 0x3F;
|
||||
$hex[3] = 0x80 | $code_point & 0x3F;
|
||||
$ret = chr($hex[0]).chr($hex[1]).chr($hex[2]).chr($hex[3]);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function testLexerForTab()
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$lexer->setInput("foo\tbar");
|
||||
$lexer->moveNext();
|
||||
$lexer->skipUntil(EmailLexer::S_HTAB);
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::S_HTAB, $lexer->token['type']);
|
||||
}
|
||||
|
||||
public function testLexerForUTF8()
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$lexer->setInput("áÇ@bar.com");
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::GENERIC, $lexer->token['type']);
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::GENERIC, $lexer->token['type']);
|
||||
}
|
||||
|
||||
public function testLexerSearchToken()
|
||||
{
|
||||
$lexer = new EmailLexer();
|
||||
$lexer->setInput("foo\tbar");
|
||||
$lexer->moveNext();
|
||||
$this->assertTrue($lexer->find(EmailLexer::S_HTAB));
|
||||
}
|
||||
|
||||
public function getTokens()
|
||||
{
|
||||
return array(
|
||||
array("foo", EmailLexer::GENERIC),
|
||||
array("\r", EmailLexer::S_CR),
|
||||
array("\t", EmailLexer::S_HTAB),
|
||||
array("\r\n", EmailLexer::CRLF),
|
||||
array("\n", EmailLexer::S_LF),
|
||||
array(" ", EmailLexer::S_SP),
|
||||
array("@", EmailLexer::S_AT),
|
||||
array("IPv6", EmailLexer::S_IPV6TAG),
|
||||
array("::", EmailLexer::S_DOUBLECOLON),
|
||||
array(":", EmailLexer::S_COLON),
|
||||
array(".", EmailLexer::S_DOT),
|
||||
array("\"", EmailLexer::S_DQUOTE),
|
||||
array("-", EmailLexer::S_HYPHEN),
|
||||
array("\\", EmailLexer::S_BACKSLASH),
|
||||
array("/", EmailLexer::S_SLASH),
|
||||
array("(", EmailLexer::S_OPENPARENTHESIS),
|
||||
array(")", EmailLexer::S_CLOSEPARENTHESIS),
|
||||
array('<', EmailLexer::S_LOWERTHAN),
|
||||
array('>', EmailLexer::S_GREATERTHAN),
|
||||
array('[', EmailLexer::S_OPENBRACKET),
|
||||
array(']', EmailLexer::S_CLOSEBRACKET),
|
||||
array(';', EmailLexer::S_SEMICOLON),
|
||||
array(',', EmailLexer::S_COMMA),
|
||||
array('<', EmailLexer::S_LOWERTHAN),
|
||||
array('>', EmailLexer::S_GREATERTHAN),
|
||||
array('{', EmailLexer::S_OPENQBRACKET),
|
||||
array('}', EmailLexer::S_CLOSEQBRACKET),
|
||||
array('', EmailLexer::S_EMPTY),
|
||||
array(chr(31), EmailLexer::INVALID),
|
||||
array(chr(226), EmailLexer::GENERIC),
|
||||
array(chr(0), EmailLexer::C_NUL)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,375 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Egulias\Tests\EmailValidator;
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $validator;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->validator = new EmailValidator();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->validator = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidEmails
|
||||
*/
|
||||
public function testValidEmails($email)
|
||||
{
|
||||
$this->assertTrue($this->validator->isValid($email));
|
||||
}
|
||||
|
||||
public function testInvalidUTF8Email()
|
||||
{
|
||||
$validator = new EmailValidator;
|
||||
$email = "\x80\x81\x82@\x83\x84\x85.\x86\x87\x88";
|
||||
|
||||
$this->assertFalse($validator->isValid($email));
|
||||
}
|
||||
|
||||
public function getValidEmails()
|
||||
{
|
||||
return array(
|
||||
array('â@iana.org'),
|
||||
array('fabien@symfony.com'),
|
||||
array('example@example.co.uk'),
|
||||
array('fabien_potencier@example.fr'),
|
||||
array('example@localhost'),
|
||||
array('fab\'ien@symfony.com'),
|
||||
array('fab\ ien@symfony.com'),
|
||||
array('example((example))@fakedfake.co.uk'),
|
||||
array('example@faked(fake).co.uk'),
|
||||
array('fabien+@symfony.com'),
|
||||
array('инфо@письмо.рф'),
|
||||
array('"username"@example.com'),
|
||||
array('"user,name"@example.com'),
|
||||
array('"user name"@example.com'),
|
||||
array('"user@name"@example.com'),
|
||||
array('"\a"@iana.org'),
|
||||
array('"test\ test"@iana.org'),
|
||||
array('""@iana.org'),
|
||||
array('"\""@iana.org'),
|
||||
array('müller@möller.de'),
|
||||
array('test@email*'),
|
||||
array('test@email!'),
|
||||
array('test@email&'),
|
||||
array('test@email^'),
|
||||
array('test@email%'),
|
||||
array('test@email$'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidEmails
|
||||
*/
|
||||
public function testInvalidEmails($email)
|
||||
{
|
||||
$this->assertFalse($this->validator->isValid($email));
|
||||
}
|
||||
|
||||
public function getInvalidEmails()
|
||||
{
|
||||
return array(
|
||||
array('test@example.com test'),
|
||||
array('user name@example.com'),
|
||||
array('user name@example.com'),
|
||||
array('example.@example.co.uk'),
|
||||
array('example@example@example.co.uk'),
|
||||
array('(test_exampel@example.fr)'),
|
||||
array('example(example)example@example.co.uk'),
|
||||
array('.example@localhost'),
|
||||
array('ex\ample@localhost'),
|
||||
array('example@local\host'),
|
||||
array('example@localhost.'),
|
||||
array('user name@example.com'),
|
||||
array('username@ example . com'),
|
||||
array('example@(fake).com'),
|
||||
array('example@(fake.com'),
|
||||
array('username@example,com'),
|
||||
array('usern,ame@example.com'),
|
||||
array('user[na]me@example.com'),
|
||||
array('"""@iana.org'),
|
||||
array('"\"@iana.org'),
|
||||
array('"test"test@iana.org'),
|
||||
array('"test""test"@iana.org'),
|
||||
array('"test"."test"@iana.org'),
|
||||
array('"test".test@iana.org'),
|
||||
array('"test"' . chr(0) . '@iana.org'),
|
||||
array('"test\"@iana.org'),
|
||||
array(chr(226) . '@iana.org'),
|
||||
array('test@' . chr(226) . '.org'),
|
||||
array('\r\ntest@iana.org'),
|
||||
array('\r\n test@iana.org'),
|
||||
array('\r\n \r\ntest@iana.org'),
|
||||
array('\r\n \r\ntest@iana.org'),
|
||||
array('\r\n \r\n test@iana.org'),
|
||||
array('test@iana.org \r\n'),
|
||||
array('test@iana.org \r\n '),
|
||||
array('test@iana.org \r\n \r\n'),
|
||||
array('test@iana.org \r\n\r\n'),
|
||||
array('test@iana.org \r\n\r\n '),
|
||||
array('test@iana/icann.org'),
|
||||
array('test@foo;bar.com'),
|
||||
array('test;123@foobar.com'),
|
||||
array('test@example..com'),
|
||||
array('email.email@email."'),
|
||||
array('test@email>'),
|
||||
array('test@email<'),
|
||||
array('test@email{'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidEmailsWithErrors
|
||||
*/
|
||||
public function testInvalidEmailsWithErrorsCheck($errors, $email)
|
||||
{
|
||||
$this->assertFalse($this->validator->isValid($email));
|
||||
|
||||
$this->assertEquals($errors, $this->validator->getError());
|
||||
}
|
||||
|
||||
public function getInvalidEmailsWithErrors()
|
||||
{
|
||||
return array(
|
||||
array(EmailValidator::ERR_NOLOCALPART, '@example.co.uk'),
|
||||
array(EmailValidator::ERR_NODOMAIN, 'example@'),
|
||||
array(EmailValidator::ERR_DOMAINHYPHENEND, 'example@example-.co.uk'),
|
||||
array(EmailValidator::ERR_DOMAINHYPHENEND, 'example@example-'),
|
||||
array(EmailValidator::ERR_CONSECUTIVEATS, 'example@@example.co.uk'),
|
||||
array(EmailValidator::ERR_CONSECUTIVEDOTS, 'example..example@example.co.uk'),
|
||||
array(EmailValidator::ERR_CONSECUTIVEDOTS, 'example@example..co.uk'),
|
||||
array(EmailValidator::ERR_EXPECTING_ATEXT, '<fabien_potencier>@example.fr'),
|
||||
array(EmailValidator::ERR_DOT_START, '.example@localhost'),
|
||||
array(EmailValidator::ERR_DOT_START, 'example@.localhost'),
|
||||
array(EmailValidator::ERR_DOT_END, 'example@localhost.'),
|
||||
array(EmailValidator::ERR_DOT_END, 'example.@example.co.uk'),
|
||||
array(EmailValidator::ERR_UNCLOSEDCOMMENT, '(example@localhost'),
|
||||
array(EmailValidator::ERR_UNCLOSEDQUOTEDSTR, '"example@localhost'),
|
||||
array(EmailValidator::ERR_EXPECTING_ATEXT, 'exa"mple@localhost'),
|
||||
//This was the original. But atext is not allowed after \n
|
||||
//array(EmailValidator::ERR_EXPECTING_ATEXT, "exampl\ne@example.co.uk"),
|
||||
array(EmailValidator::ERR_ATEXT_AFTER_CFWS, "exampl\ne@example.co.uk"),
|
||||
array(EmailValidator::ERR_EXPECTING_DTEXT, "example@[[]"),
|
||||
array(EmailValidator::ERR_ATEXT_AFTER_CFWS, "exampl\te@example.co.uk"),
|
||||
array(EmailValidator::ERR_CR_NO_LF, "example@exa\rmple.co.uk"),
|
||||
array(EmailValidator::ERR_CR_NO_LF, "example@[\r]"),
|
||||
array(EmailValidator::ERR_CR_NO_LF, "exam\rple@example.co.uk"),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidEmailsWithWarnings
|
||||
*/
|
||||
public function testValidEmailsWithWarningsCheck($warnings, $email)
|
||||
{
|
||||
$this->assertTrue($this->validator->isValid($email, true));
|
||||
|
||||
$this->assertEquals($warnings, $this->validator->getWarnings());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidEmailsWithWarnings
|
||||
*/
|
||||
public function testInvalidEmailsWithDnsCheckAndStrictMode($warnings, $email)
|
||||
{
|
||||
$this->assertFalse($this->validator->isValid($email, true, true));
|
||||
|
||||
$this->assertEquals($warnings, $this->validator->getWarnings());
|
||||
}
|
||||
|
||||
public function getInvalidEmailsWithWarnings()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
EmailValidator::DEPREC_CFWS_NEAR_AT,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'example @example.co.uk'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::DEPREC_CFWS_NEAR_AT,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'example@ example.co.uk'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::CFWS_COMMENT,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'example@example(examplecomment).co.uk'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::CFWS_COMMENT,
|
||||
EmailValidator::DEPREC_CFWS_NEAR_AT,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example(examplecomment)@example.co.uk'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_QUOTEDSTRING,
|
||||
EmailValidator::CFWS_FWS,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
"\"\t\"@example.co.uk"
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_QUOTEDSTRING,
|
||||
EmailValidator::CFWS_FWS,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
"\"\r\"@example.co.uk"
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_ADDRESSLITERAL,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[127.0.0.1]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_ADDRESSLITERAL,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_ADDRESSLITERAL,
|
||||
EmailValidator::RFC5321_IPV6DEPRECATED,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370::]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_ADDRESSLITERAL,
|
||||
EmailValidator::RFC5322_IPV6_MAXGRPS,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334::]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_ADDRESSLITERAL,
|
||||
EmailValidator::RFC5322_IPV6_2X2XCOLON,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[IPv6:1::1::1]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5322_DOMLIT_OBSDTEXT,
|
||||
EmailValidator::RFC5322_DOMAINLITERAL,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
"example@[\n]"
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5322_DOMAINLITERAL,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[::1]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5322_DOMAINLITERAL,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[::123.45.67.178]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5322_IPV6_COLONSTRT,
|
||||
EmailValidator::RFC5321_ADDRESSLITERAL,
|
||||
EmailValidator::RFC5322_IPV6_GRPCOUNT,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[IPv6::2001:0db8:85a3:0000:0000:8a2e:0370:7334]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_ADDRESSLITERAL,
|
||||
EmailValidator::RFC5322_IPV6_BADCHAR,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[IPv6:z001:0db8:85a3:0000:0000:8a2e:0370:7334]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_ADDRESSLITERAL,
|
||||
EmailValidator::RFC5322_IPV6_COLONEND,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:]'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5321_QUOTEDSTRING,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'"example"@example.co.uk'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5322_LOCAL_TOOLONG,
|
||||
EmailValidator::DNSWARN_NO_RECORD
|
||||
),
|
||||
'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@example.co.uk'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5322_LABEL_TOOLONG,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart.co.uk'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5322_DOMAIN_TOOLONG,
|
||||
EmailValidator::RFC5322_TOOLONG,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocal'.
|
||||
'parttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart'.
|
||||
'toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::RFC5322_DOMAIN_TOOLONG,
|
||||
EmailValidator::RFC5322_TOOLONG,
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'example@toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocal'.
|
||||
'parttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart'.
|
||||
'toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpar'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
EmailValidator::DNSWARN_NO_RECORD,
|
||||
),
|
||||
'test@test'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidEmailsWithStrict()
|
||||
{
|
||||
$this->assertFalse($this->validator->isValid('"test"@test', false, true));
|
||||
}
|
||||
}
|
Reference in a new issue