mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-06 15:52:50 +00:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5631c3fe2e | |||
| c383717824 | |||
| aabed98198 | |||
| 3b0fd01aa3 | |||
| 4efe697504 | |||
| 7a4c5714f5 | |||
| 0a26375a7a | |||
| 773fe5f4a3 | |||
| 4a209951ee | |||
| a8b0bab5aa | |||
| cc0b91f311 | |||
| 8092ecaeff | |||
| f19defb373 | |||
| 9a518fb1bd | |||
| 9b184605e8 | |||
| 7a4842c60f | |||
| 687ab6a66e | |||
| 116d4054fa | |||
| af9417f765 | |||
| ab0bcfb424 | |||
| 833b3e7924 | |||
| fec1609458 | |||
| add559b99c | |||
| 19e390d863 | |||
| 5320c26b38 | |||
| 3b6ab3bcd5 | |||
| 7a64ea18af | |||
| 9103f4f99b | |||
| 3f623e9006 | |||
| 833eb65135 | |||
| e61481fefb | |||
| 518f80a0ff | |||
| 2ec7babda6 | |||
| 05367768d6 |
+19
-3
@@ -1,3 +1,5 @@
|
|||||||
|
sudo: false
|
||||||
|
|
||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
@@ -5,11 +7,25 @@ php:
|
|||||||
- 5.4
|
- 5.4
|
||||||
- 5.5
|
- 5.5
|
||||||
- 5.6
|
- 5.6
|
||||||
|
- 7.0
|
||||||
- hhvm
|
- hhvm
|
||||||
|
|
||||||
before_script:
|
env:
|
||||||
- wget http://getcomposer.org/composer.phar
|
global:
|
||||||
- php composer.phar install --dev --no-interaction
|
- deps=no
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
fast_finish: true
|
||||||
|
include:
|
||||||
|
- php: 5.3
|
||||||
|
env: deps=low
|
||||||
|
- php: 5.6
|
||||||
|
env: deps=high
|
||||||
|
|
||||||
|
install:
|
||||||
|
- if [ "$deps" = "no" ]; then composer install; fi
|
||||||
|
- if [ "$deps" = "low" ]; then composer update --prefer-lowest; fi
|
||||||
|
- if [ "$deps" = "high" ]; then composer update; fi
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- mkdir -p build/logs
|
- mkdir -p build/logs
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
EmailValidator [](https://travis-ci.org/egulias/EmailValidator) [](https://coveralls.io/r/egulias/EmailValidator?branch=master) [](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)[](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master)
|
#EmailValidator
|
||||||
|
[](https://travis-ci.org/egulias/EmailValidator) [](https://coveralls.io/r/egulias/EmailValidator?branch=master) [](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master) [](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)
|
||||||
=============================
|
=============================
|
||||||
|
With the help of
|
||||||
|
|
||||||
|

|
||||||
##Installation##
|
##Installation##
|
||||||
|
|
||||||
Run the command below to install via Composer
|
Run the command below to install via Composer
|
||||||
|
|||||||
+3
-2
@@ -15,10 +15,11 @@
|
|||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">= 5.3.3",
|
"php": ">= 5.3.3",
|
||||||
"doctrine/lexer": "~1.0"
|
"doctrine/lexer": "~1.0,>=1.0.1"
|
||||||
},
|
},
|
||||||
"require-dev" : {
|
"require-dev" : {
|
||||||
"satooshi/php-coveralls": "dev-master"
|
"satooshi/php-coveralls": "dev-master",
|
||||||
|
"phpunit/phpunit": "~4.4"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
|
|||||||
Generated
+860
-63
File diff suppressed because it is too large
Load Diff
@@ -75,8 +75,6 @@ class EmailLexer extends AbstractLexer
|
|||||||
'\0' => self::C_NUL,
|
'\0' => self::C_NUL,
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $invalidASCII = array(226 => 1,);
|
|
||||||
|
|
||||||
protected $hasInvalidTokens = false;
|
protected $hasInvalidTokens = false;
|
||||||
|
|
||||||
protected $previous;
|
protected $previous;
|
||||||
@@ -138,12 +136,12 @@ class EmailLexer extends AbstractLexer
|
|||||||
protected function getCatchablePatterns()
|
protected function getCatchablePatterns()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'[a-zA-Z_]+[46]?',
|
'[a-zA-Z_]+[46]?', //ASCII and domain literal
|
||||||
|
'[^\x00-\x7F]', //UTF-8
|
||||||
'[0-9]+',
|
'[0-9]+',
|
||||||
'\r\n',
|
'\r\n',
|
||||||
'::',
|
'::',
|
||||||
'\s+',
|
'\s+?',
|
||||||
'[\x10-\x1F]+',
|
|
||||||
'.',
|
'.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -155,7 +153,7 @@ class EmailLexer extends AbstractLexer
|
|||||||
*/
|
*/
|
||||||
protected function getNonCatchablePatterns()
|
protected function getNonCatchablePatterns()
|
||||||
{
|
{
|
||||||
return array('[\x7f-\xff]+');
|
return array('[\xA0-\xff]+');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,16 +165,15 @@ class EmailLexer extends AbstractLexer
|
|||||||
*/
|
*/
|
||||||
protected function getType(&$value)
|
protected function getType(&$value)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->isNullType($value)) {
|
if ($this->isNullType($value)) {
|
||||||
return self::C_NUL;
|
return self::C_NUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->charValue[$value])) {
|
if ($this->isValid($value)) {
|
||||||
return $this->charValue[$value];
|
return $this->charValue[$value];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isInvalid($value)) {
|
if ($this->isUTF8Invalid($value)) {
|
||||||
$this->hasInvalidTokens = true;
|
$this->hasInvalidTokens = true;
|
||||||
return self::INVALID;
|
return self::INVALID;
|
||||||
}
|
}
|
||||||
@@ -184,8 +181,18 @@ class EmailLexer extends AbstractLexer
|
|||||||
return self::GENERIC;
|
return self::GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isValid($value)
|
||||||
|
{
|
||||||
|
if (isset($this->charValue[$value])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $value
|
* @param $value
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isNullType($value)
|
protected function isNullType($value)
|
||||||
{
|
{
|
||||||
@@ -197,18 +204,20 @@ class EmailLexer extends AbstractLexer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $value
|
* @param $value
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isInvalid($value)
|
protected function isUTF8Invalid($value)
|
||||||
{
|
{
|
||||||
if (preg_match('/[\x10-\x1F]+/', $value)) {
|
if (preg_match('/\p{Cc}+/u', $value)) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->invalidASCII[ord($value)])) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getModifiers()
|
||||||
|
{
|
||||||
|
return 'iu';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ class EmailParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $str
|
* @param $str
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function parse($str)
|
public function parse($str)
|
||||||
{
|
{
|
||||||
@@ -39,15 +40,16 @@ class EmailParser
|
|||||||
throw new \InvalidArgumentException('ERR_NOLOCALPART');
|
throw new \InvalidArgumentException('ERR_NOLOCALPART');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->lexer->hasInvalidTokens()) {
|
|
||||||
throw new \InvalidArgumentException('ERR_INVALID_ATEXT');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->localPartParser->parse($str);
|
$this->localPartParser->parse($str);
|
||||||
$this->domainPartParser->parse($str);
|
$this->domainPartParser->parse($str);
|
||||||
|
|
||||||
$this->setParts($str);
|
$this->setParts($str);
|
||||||
|
|
||||||
|
if ($this->lexer->hasInvalidTokens()) {
|
||||||
|
throw new \InvalidArgumentException('ERR_INVALID_ATEXT');
|
||||||
|
}
|
||||||
|
|
||||||
return array('local' => $this->localPart, 'domain' => $this->domainPart);
|
return array('local' => $this->localPart, 'domain' => $this->domainPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class EmailValidator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dns = false;
|
$dns = true;
|
||||||
if ($checkDNS) {
|
if ($checkDNS) {
|
||||||
$dns = $this->checkDNS();
|
$dns = $this->checkDNS();
|
||||||
}
|
}
|
||||||
@@ -95,12 +95,7 @@ class EmailValidator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($strict) ? $this->checkStrict($dns) : true;
|
return !$strict || (!$this->hasWarnings() && $dns);
|
||||||
}
|
|
||||||
|
|
||||||
private function checkStrict($dns)
|
|
||||||
{
|
|
||||||
return !($this->hasWarnings() && !$dns);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ class DomainPart extends Parser
|
|||||||
{
|
{
|
||||||
$domain = '';
|
$domain = '';
|
||||||
do {
|
do {
|
||||||
|
|
||||||
$prev = $this->lexer->getPrevious();
|
$prev = $this->lexer->getPrevious();
|
||||||
|
|
||||||
if ($this->lexer->token['type'] === EmailLexer::S_SLASH) {
|
if ($this->lexer->token['type'] === EmailLexer::S_SLASH) {
|
||||||
@@ -217,9 +218,6 @@ class DomainPart extends Parser
|
|||||||
return $addressLiteral;
|
return $addressLiteral;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $addressLiteral
|
|
||||||
*/
|
|
||||||
protected function checkIPV4Tag($addressLiteral)
|
protected function checkIPV4Tag($addressLiteral)
|
||||||
{
|
{
|
||||||
$matchesIP = array();
|
$matchesIP = array();
|
||||||
@@ -245,6 +243,17 @@ class DomainPart extends Parser
|
|||||||
|
|
||||||
protected function checkDomainPartExceptions($prev)
|
protected function checkDomainPartExceptions($prev)
|
||||||
{
|
{
|
||||||
|
$invalidDomainTokens = array(
|
||||||
|
EmailLexer::S_DQUOTE => true,
|
||||||
|
EmailLexer::S_SEMICOLON => true,
|
||||||
|
EmailLexer::S_GREATERTHAN => true,
|
||||||
|
EmailLexer::S_LOWERTHAN => true,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($invalidDomainTokens[$this->lexer->token['type']])) {
|
||||||
|
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->lexer->token['type'] === EmailLexer::S_COMMA) {
|
if ($this->lexer->token['type'] === EmailLexer::S_COMMA) {
|
||||||
throw new \InvalidArgumentException('ERR_COMMA_IN_DOMAIN');
|
throw new \InvalidArgumentException('ERR_COMMA_IN_DOMAIN');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use Egulias\EmailValidator\EmailLexer;
|
|||||||
use Egulias\EmailValidator\EmailValidator;
|
use Egulias\EmailValidator\EmailValidator;
|
||||||
use \InvalidArgumentException;
|
use \InvalidArgumentException;
|
||||||
|
|
||||||
|
|
||||||
class LocalPart extends Parser
|
class LocalPart extends Parser
|
||||||
{
|
{
|
||||||
public function parse($localPart)
|
public function parse($localPart)
|
||||||
|
|||||||
@@ -26,6 +26,73 @@ class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($token, $lexer->token['type']);
|
$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()
|
public function testLexerForTab()
|
||||||
{
|
{
|
||||||
$lexer = new EmailLexer();
|
$lexer = new EmailLexer();
|
||||||
@@ -36,6 +103,17 @@ class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(EmailLexer::S_HTAB, $lexer->token['type']);
|
$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()
|
public function testLexerSearchToken()
|
||||||
{
|
{
|
||||||
$lexer = new EmailLexer();
|
$lexer = new EmailLexer();
|
||||||
@@ -44,15 +122,6 @@ class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($lexer->find(EmailLexer::S_HTAB));
|
$this->assertTrue($lexer->find(EmailLexer::S_HTAB));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLexerHasInvalidTokens()
|
|
||||||
{
|
|
||||||
$lexer = new EmailLexer();
|
|
||||||
$lexer->setInput(chr(226));
|
|
||||||
$lexer->moveNext();
|
|
||||||
$lexer->moveNext();
|
|
||||||
$this->assertTrue($lexer->hasInvalidTokens());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTokens()
|
public function getTokens()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
@@ -85,7 +154,7 @@ class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
|||||||
array('}', EmailLexer::S_CLOSEQBRACKET),
|
array('}', EmailLexer::S_CLOSEQBRACKET),
|
||||||
array('', EmailLexer::S_EMPTY),
|
array('', EmailLexer::S_EMPTY),
|
||||||
array(chr(31), EmailLexer::INVALID),
|
array(chr(31), EmailLexer::INVALID),
|
||||||
array(chr(226), EmailLexer::INVALID),
|
array(chr(226), EmailLexer::GENERIC),
|
||||||
array(chr(0), EmailLexer::C_NUL)
|
array(chr(0), EmailLexer::C_NUL)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,18 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($this->validator->isValid($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()
|
public function getValidEmails()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
array('â@iana.org'),
|
||||||
array('fabien@symfony.com'),
|
array('fabien@symfony.com'),
|
||||||
array('example@example.co.uk'),
|
array('example@example.co.uk'),
|
||||||
array('fabien_potencier@example.fr'),
|
array('fabien_potencier@example.fr'),
|
||||||
@@ -47,6 +56,13 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('"test\ test"@iana.org'),
|
array('"test\ test"@iana.org'),
|
||||||
array('""@iana.org'),
|
array('""@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$'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +77,9 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function getInvalidEmails()
|
public function getInvalidEmails()
|
||||||
{
|
{
|
||||||
return array(
|
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.co.uk'),
|
||||||
array('example@example@example.co.uk'),
|
array('example@example@example.co.uk'),
|
||||||
array('(test_exampel@example.fr)'),
|
array('(test_exampel@example.fr)'),
|
||||||
@@ -98,6 +116,13 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
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.org \r\n\r\n '),
|
||||||
array('test@iana/icann.org'),
|
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{'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,16 +175,45 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($warnings, $this->validator->getWarnings());
|
$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()
|
public function getInvalidEmailsWithWarnings()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(array( EmailValidator::DEPREC_CFWS_NEAR_AT,), 'example @example.co.uk'),
|
array(
|
||||||
array(array( EmailValidator::DEPREC_CFWS_NEAR_AT,), 'example@ example.co.uk'),
|
array(
|
||||||
array(array( EmailValidator::CFWS_COMMENT,), 'example@example(examplecomment).co.uk'),
|
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(
|
||||||
array(
|
array(
|
||||||
EmailValidator::CFWS_COMMENT,
|
EmailValidator::CFWS_COMMENT,
|
||||||
EmailValidator::DEPREC_CFWS_NEAR_AT,
|
EmailValidator::DEPREC_CFWS_NEAR_AT,
|
||||||
|
EmailValidator::DNSWARN_NO_RECORD,
|
||||||
),
|
),
|
||||||
'example(examplecomment)@example.co.uk'
|
'example(examplecomment)@example.co.uk'
|
||||||
),
|
),
|
||||||
@@ -167,6 +221,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
EmailValidator::RFC5321_QUOTEDSTRING,
|
EmailValidator::RFC5321_QUOTEDSTRING,
|
||||||
EmailValidator::CFWS_FWS,
|
EmailValidator::CFWS_FWS,
|
||||||
|
EmailValidator::DNSWARN_NO_RECORD,
|
||||||
),
|
),
|
||||||
"\"\t\"@example.co.uk"
|
"\"\t\"@example.co.uk"
|
||||||
),
|
),
|
||||||
@@ -174,6 +229,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
EmailValidator::RFC5321_QUOTEDSTRING,
|
EmailValidator::RFC5321_QUOTEDSTRING,
|
||||||
EmailValidator::CFWS_FWS,
|
EmailValidator::CFWS_FWS,
|
||||||
|
EmailValidator::DNSWARN_NO_RECORD
|
||||||
),
|
),
|
||||||
"\"\r\"@example.co.uk"
|
"\"\r\"@example.co.uk"
|
||||||
),
|
),
|
||||||
@@ -265,12 +321,14 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
EmailValidator::RFC5321_QUOTEDSTRING,
|
EmailValidator::RFC5321_QUOTEDSTRING,
|
||||||
|
EmailValidator::DNSWARN_NO_RECORD
|
||||||
),
|
),
|
||||||
'"example"@example.co.uk'
|
'"example"@example.co.uk'
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
EmailValidator::RFC5322_LOCAL_TOOLONG,
|
EmailValidator::RFC5322_LOCAL_TOOLONG,
|
||||||
|
EmailValidator::DNSWARN_NO_RECORD
|
||||||
),
|
),
|
||||||
'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@example.co.uk'
|
'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@example.co.uk'
|
||||||
),
|
),
|
||||||
@@ -301,14 +359,15 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
'parttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart'.
|
'parttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart'.
|
||||||
'toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpar'
|
'toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpar'
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
EmailValidator::DNSWARN_NO_RECORD,
|
||||||
|
),
|
||||||
|
'test@test'
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidEmailsWithDNSAndStrict()
|
|
||||||
{
|
|
||||||
$this->assertFalse($this->validator->isValid('test@test', true, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testInvalidEmailsWithStrict()
|
public function testInvalidEmailsWithStrict()
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->validator->isValid('"test"@test', false, true));
|
$this->assertFalse($this->validator->isValid('"test"@test', false, true));
|
||||||
|
|||||||
Reference in New Issue
Block a user