mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-04 22:50:45 +00:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de448a30fa | |||
| a7b385301d | |||
| f6447f8b99 | |||
| d4001715b2 | |||
| 4b7fcf6796 | |||
| 2a1145ffbf | |||
| af864423f5 | |||
| 12f16f70aa | |||
| 0afaa6a3b6 | |||
| 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 |
+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,12 +1,15 @@
|
|||||||
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
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
composer require egulias/email-validator
|
composer require egulias/email-validator "~1.2"
|
||||||
```
|
```
|
||||||
|
|
||||||
##Usage##
|
##Usage##
|
||||||
|
|||||||
+5
-4
@@ -3,22 +3,23 @@
|
|||||||
"description": "A library for validating emails",
|
"description": "A library for validating emails",
|
||||||
"homepage": "https://github.com/egulias/EmailValidator",
|
"homepage": "https://github.com/egulias/EmailValidator",
|
||||||
"type": "Library",
|
"type": "Library",
|
||||||
"keywords": ["email", "validation", "validator"],
|
"keywords": ["email", "validation", "validator", "emailvalidation", "emailvalidator"],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{"name": "Eduardo Gulias Davis"}
|
{"name": "Eduardo Gulias Davis"}
|
||||||
],
|
],
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "1.3.x-dev"
|
"dev-master": "2.0.x-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">= 5.3.3",
|
"php": ">= 5.3.3",
|
||||||
"doctrine/lexer": "dev-master"
|
"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
+1017
-102
File diff suppressed because it is too large
Load Diff
@@ -67,16 +67,12 @@ class EmailLexer extends AbstractLexer
|
|||||||
"\n" => self::S_LF,
|
"\n" => self::S_LF,
|
||||||
"\r\n" => self::CRLF,
|
"\r\n" => self::CRLF,
|
||||||
'IPv6' => self::S_IPV6TAG,
|
'IPv6' => self::S_IPV6TAG,
|
||||||
'<' => self::S_LOWERTHAN,
|
|
||||||
'>' => self::S_GREATERTHAN,
|
|
||||||
'{' => self::S_OPENQBRACKET,
|
'{' => self::S_OPENQBRACKET,
|
||||||
'}' => self::S_CLOSEQBRACKET,
|
'}' => self::S_CLOSEQBRACKET,
|
||||||
'' => self::S_EMPTY,
|
'' => self::S_EMPTY,
|
||||||
'\0' => self::C_NUL,
|
'\0' => self::C_NUL,
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $invalidASCII = array(226 => 1,);
|
|
||||||
|
|
||||||
protected $hasInvalidTokens = false;
|
protected $hasInvalidTokens = false;
|
||||||
|
|
||||||
protected $previous;
|
protected $previous;
|
||||||
@@ -138,7 +134,8 @@ 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',
|
||||||
'::',
|
'::',
|
||||||
@@ -179,11 +176,6 @@ class EmailLexer extends AbstractLexer
|
|||||||
return self::INVALID;
|
return self::INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isASCIIInvalid($value)) {
|
|
||||||
$this->hasInvalidTokens = true;
|
|
||||||
return self::INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::GENERIC;
|
return self::GENERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,19 +201,6 @@ class EmailLexer extends AbstractLexer
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function isASCIIInvalid($value)
|
|
||||||
{
|
|
||||||
if (isset($this->invalidASCII[ord($value)])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class EmailValidator
|
|||||||
const ERR_FWS_CRLF_END = 149;
|
const ERR_FWS_CRLF_END = 149;
|
||||||
const ERR_CR_NO_LF = 150;
|
const ERR_CR_NO_LF = 150;
|
||||||
const ERR_DEPREC_REACHED = 151;
|
const ERR_DEPREC_REACHED = 151;
|
||||||
|
const ERR_UNOPENEDCOMMENT = 152;
|
||||||
const RFC5321_TLD = 9;
|
const RFC5321_TLD = 9;
|
||||||
const RFC5321_TLDNUMERIC = 10;
|
const RFC5321_TLDNUMERIC = 10;
|
||||||
const RFC5321_QUOTEDSTRING = 11;
|
const RFC5321_QUOTEDSTRING = 11;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
namespace Egulias\EmailValidator\Parser;
|
namespace Egulias\EmailValidator\Parser;
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
use Egulias\EmailValidator\EmailLexer;
|
||||||
use Egulias\EmailValidator\Parser\Parser;
|
|
||||||
use Egulias\EmailValidator\EmailValidator;
|
use Egulias\EmailValidator\EmailValidator;
|
||||||
|
|
||||||
class DomainPart extends Parser
|
class DomainPart extends Parser
|
||||||
@@ -103,6 +102,7 @@ class DomainPart extends Parser
|
|||||||
protected function doParseDomainPart()
|
protected function doParseDomainPart()
|
||||||
{
|
{
|
||||||
$domain = '';
|
$domain = '';
|
||||||
|
$openedParenthesis = 0;
|
||||||
do {
|
do {
|
||||||
$prev = $this->lexer->getPrevious();
|
$prev = $this->lexer->getPrevious();
|
||||||
|
|
||||||
@@ -112,7 +112,19 @@ class DomainPart extends Parser
|
|||||||
|
|
||||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||||
$this->parseComments();
|
$this->parseComments();
|
||||||
|
$openedParenthesis += $this->getOpenedParenthesis();
|
||||||
$this->lexer->moveNext();
|
$this->lexer->moveNext();
|
||||||
|
$tmpPrev = $this->lexer->getPrevious();
|
||||||
|
if ($tmpPrev['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||||
|
$openedParenthesis--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||||
|
if ($openedParenthesis === 0) {
|
||||||
|
throw new \InvalidArgumentException('ERR_UNOPENEDCOMMENT');
|
||||||
|
} else {
|
||||||
|
$openedParenthesis--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checkConsecutiveDots();
|
$this->checkConsecutiveDots();
|
||||||
@@ -179,7 +191,7 @@ class DomainPart extends Parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
|
if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
|
||||||
throw new \InvalidArgumentException("ERR_CR_NO_LF");
|
throw new \InvalidArgumentException('ERR_CR_NO_LF');
|
||||||
}
|
}
|
||||||
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
|
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
|
||||||
$this->warnings[] = EmailValidator::RFC5322_DOMLIT_OBSDTEXT;
|
$this->warnings[] = EmailValidator::RFC5322_DOMLIT_OBSDTEXT;
|
||||||
@@ -217,9 +229,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 +254,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');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace Egulias\EmailValidator\Parser;
|
|||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
use Egulias\EmailValidator\EmailLexer;
|
||||||
use Egulias\EmailValidator\EmailValidator;
|
use Egulias\EmailValidator\EmailValidator;
|
||||||
use \InvalidArgumentException;
|
|
||||||
|
|
||||||
class LocalPart extends Parser
|
class LocalPart extends Parser
|
||||||
{
|
{
|
||||||
@@ -12,9 +11,9 @@ class LocalPart extends Parser
|
|||||||
{
|
{
|
||||||
$parseDQuote = true;
|
$parseDQuote = true;
|
||||||
$closingQuote = false;
|
$closingQuote = false;
|
||||||
|
$openedParenthesis = 0;
|
||||||
|
|
||||||
while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) {
|
while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) {
|
||||||
|
|
||||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) {
|
if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) {
|
||||||
throw new \InvalidArgumentException('ERR_DOT_START');
|
throw new \InvalidArgumentException('ERR_DOT_START');
|
||||||
}
|
}
|
||||||
@@ -26,12 +25,19 @@ class LocalPart extends Parser
|
|||||||
|
|
||||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||||
$this->parseComments();
|
$this->parseComments();
|
||||||
|
$openedParenthesis += $this->getOpenedParenthesis();
|
||||||
|
}
|
||||||
|
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||||
|
if ($openedParenthesis === 0) {
|
||||||
|
throw new \InvalidArgumentException('ERR_UNOPENEDCOMMENT');
|
||||||
|
} else {
|
||||||
|
$openedParenthesis--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checkConsecutiveDots();
|
$this->checkConsecutiveDots();
|
||||||
|
|
||||||
if (
|
if ($this->lexer->token['type'] === EmailLexer::S_DOT &&
|
||||||
$this->lexer->token['type'] === EmailLexer::S_DOT &&
|
|
||||||
$this->lexer->isNextToken(EmailLexer::S_AT)
|
$this->lexer->isNextToken(EmailLexer::S_AT)
|
||||||
) {
|
) {
|
||||||
throw new \InvalidArgumentException('ERR_DOT_END');
|
throw new \InvalidArgumentException('ERR_DOT_END');
|
||||||
@@ -82,7 +88,7 @@ class LocalPart extends Parser
|
|||||||
$this->lexer->moveNext();
|
$this->lexer->moveNext();
|
||||||
|
|
||||||
if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) {
|
if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) {
|
||||||
throw new InvalidArgumentException("ERR_EXPECTED_ATEXT");
|
throw new \InvalidArgumentException('ERR_EXPECTED_ATEXT');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,12 +96,12 @@ class LocalPart extends Parser
|
|||||||
|
|
||||||
if ($prev['type'] === EmailLexer::S_BACKSLASH) {
|
if ($prev['type'] === EmailLexer::S_BACKSLASH) {
|
||||||
if (!$this->checkDQUOTE(false)) {
|
if (!$this->checkDQUOTE(false)) {
|
||||||
throw new \InvalidArgumentException("ERR_UNCLOSED_DQUOTE");
|
throw new \InvalidArgumentException('ERR_UNCLOSED_DQUOTE');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
|
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
|
||||||
throw new \InvalidArgumentException("ERR_EXPECED_AT");
|
throw new \InvalidArgumentException('ERR_EXPECED_AT');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $parseAgain;
|
return $parseAgain;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ abstract class Parser
|
|||||||
{
|
{
|
||||||
protected $warnings = array();
|
protected $warnings = array();
|
||||||
protected $lexer;
|
protected $lexer;
|
||||||
|
protected $openedParenthesis = 0;
|
||||||
|
|
||||||
public function __construct(EmailLexer $lexer)
|
public function __construct(EmailLexer $lexer)
|
||||||
{
|
{
|
||||||
@@ -20,7 +21,13 @@ abstract class Parser
|
|||||||
return $this->warnings;
|
return $this->warnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract function parse($str);
|
abstract public function parse($str);
|
||||||
|
|
||||||
|
/** @return int */
|
||||||
|
public function getOpenedParenthesis()
|
||||||
|
{
|
||||||
|
return $this->openedParenthesis;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* validateQuotedPair
|
* validateQuotedPair
|
||||||
@@ -35,15 +42,15 @@ abstract class Parser
|
|||||||
$this->warnings[] = EmailValidator::DEPREC_QP;
|
$this->warnings[] = EmailValidator::DEPREC_QP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string the the comment
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
protected function parseComments()
|
protected function parseComments()
|
||||||
{
|
{
|
||||||
|
$this->openedParenthesis = 1;
|
||||||
$this->isUnclosedComment();
|
$this->isUnclosedComment();
|
||||||
$this->warnings[] = EmailValidator::CFWS_COMMENT;
|
$this->warnings[] = EmailValidator::CFWS_COMMENT;
|
||||||
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
|
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
|
||||||
|
if ($this->lexer->isNextToken(EmailLexer::S_OPENPARENTHESIS)) {
|
||||||
|
$this->openedParenthesis++;
|
||||||
|
}
|
||||||
$this->warnEscaping();
|
$this->warnEscaping();
|
||||||
$this->lexer->moveNext();
|
$this->lexer->moveNext();
|
||||||
}
|
}
|
||||||
@@ -75,11 +82,11 @@ abstract class Parser
|
|||||||
$this->checkCRLFInFWS();
|
$this->checkCRLFInFWS();
|
||||||
|
|
||||||
if ($this->lexer->token['type'] === EmailLexer::S_CR) {
|
if ($this->lexer->token['type'] === EmailLexer::S_CR) {
|
||||||
throw new \InvalidArgumentException("ERR_CR_NO_LF");
|
throw new \InvalidArgumentException('ERR_CR_NO_LF');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) {
|
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) {
|
||||||
throw new \InvalidArgumentException("ERR_ATEXT_AFTER_CFWS");
|
throw new \InvalidArgumentException('ERR_ATEXT_AFTER_CFWS');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) {
|
if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) {
|
||||||
@@ -160,7 +167,7 @@ abstract class Parser
|
|||||||
return $hasClosingQuote;
|
return $hasClosingQuote;
|
||||||
}
|
}
|
||||||
$previous = $this->lexer->getPrevious();
|
$previous = $this->lexer->getPrevious();
|
||||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
|
if ($previous['type'] === EmailLexer::GENERIC && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
||||||
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
|
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,10 +188,10 @@ abstract class Parser
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($this->lexer->isNextToken(EmailLexer::CRLF)) {
|
if ($this->lexer->isNextToken(EmailLexer::CRLF)) {
|
||||||
throw new \InvalidArgumentException("ERR_FWS_CRLF_X2");
|
throw new \InvalidArgumentException('ERR_FWS_CRLF_X2');
|
||||||
}
|
}
|
||||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
||||||
throw new \InvalidArgumentException("ERR_FWS_CRLF_END");
|
throw new \InvalidArgumentException('ERR_FWS_CRLF_END');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,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();
|
||||||
@@ -111,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(
|
||||||
@@ -152,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)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
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'),
|
||||||
@@ -55,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$'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +77,7 @@ 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('user name@example.com'),
|
array('user name@example.com'),
|
||||||
array('example.@example.co.uk'),
|
array('example.@example.co.uk'),
|
||||||
@@ -108,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{'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +152,11 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(EmailValidator::ERR_DOT_END, 'example@localhost.'),
|
array(EmailValidator::ERR_DOT_END, 'example@localhost.'),
|
||||||
array(EmailValidator::ERR_DOT_END, 'example.@example.co.uk'),
|
array(EmailValidator::ERR_DOT_END, 'example.@example.co.uk'),
|
||||||
array(EmailValidator::ERR_UNCLOSEDCOMMENT, '(example@localhost'),
|
array(EmailValidator::ERR_UNCLOSEDCOMMENT, '(example@localhost'),
|
||||||
|
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'comment)example@localhost'),
|
||||||
|
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'example(comment))@localhost'),
|
||||||
|
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'example@comment)localhost'),
|
||||||
|
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'example@localhost(comment))'),
|
||||||
|
array(EmailValidator::ERR_UNOPENEDCOMMENT, 'example@(comment))example.com'),
|
||||||
array(EmailValidator::ERR_UNCLOSEDQUOTEDSTR, '"example@localhost'),
|
array(EmailValidator::ERR_UNCLOSEDQUOTEDSTR, '"example@localhost'),
|
||||||
array(EmailValidator::ERR_EXPECTING_ATEXT, 'exa"mple@localhost'),
|
array(EmailValidator::ERR_EXPECTING_ATEXT, 'exa"mple@localhost'),
|
||||||
//This was the original. But atext is not allowed after \n
|
//This was the original. But atext is not allowed after \n
|
||||||
@@ -173,13 +193,32 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
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'
|
||||||
),
|
),
|
||||||
@@ -187,6 +226,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"
|
||||||
),
|
),
|
||||||
@@ -194,6 +234,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"
|
||||||
),
|
),
|
||||||
@@ -285,12 +326,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'
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user