Compare commits

...

3 Commits

Author SHA1 Message Date
Eduardo Gulias Davis f064a58611 FWS in localpart tests and FWS sorrounding '@' as invalid emails 2014-01-13 00:12:24 +01:00
Eduardo Gulias Davis 1a859493ee CS and minor changes 2014-01-12 18:13:13 +01:00
Eduardo Gulias Davis dd9541be28 Version branch update in README 2013-12-24 18:50:14 +01:00
6 changed files with 35 additions and 38 deletions
-2
View File
@@ -1,4 +1,2 @@
report/ report/
vendor/ vendor/
.idea
.local.php.vimrc
+3 -3
View File
@@ -1,8 +1,8 @@
EmailValidator [![Build Status](https://travis-ci.org/egulias/EmailValidator.png?branch=master)](https://travis-ci.org/egulias/EmailValidator) EmailValidator [![Build Status](https://travis-ci.org/egulias/EmailValidator.png?branch=master)](https://travis-ci.org/egulias/EmailValidator) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/b18d473e-bd5a-4d88-a7b2-7aeaee0ebd7b/small.png)](https://insight.sensiolabs.com/projects/b18d473e-bd5a-4d88-a7b2-7aeaee0ebd7b)
============================= =============================
##Installation## ##Installation##
Install via composer. Add to your current compooser.json ```require``` key: ```"egulias/email-validator":"1.0.*" ``` Install via composer. Add to your current compooser.json ```require``` key: ```"egulias/email-validator":"1.0.x-dev" ```
##Usage## ##Usage##
@@ -11,7 +11,7 @@ Simple example:
```php ```php
<?php <?php
use egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\EmailValidator;
$validator = new EmailValidator; $validator = new EmailValidator;
if ($validator->isValid($email)) { if ($validator->isValid($email)) {
+23 -23
View File
@@ -9,29 +9,29 @@ class EmailLexer extends AbstractLexer
//ASCII values //ASCII values
const C_DEL = 127; const C_DEL = 127;
const C_NUL = 0; const C_NUL = 0;
const S_AT = 64;//'@'; const S_AT = 64;
const S_BACKSLASH = 92;//'\\'; const S_BACKSLASH = 92;
const S_DOT = 46;//'.'; const S_DOT = 46;
const S_DQUOTE = 34;//'"'; const S_DQUOTE = 34;
const S_OPENPARENTHESIS = 49;//'('; const S_OPENPARENTHESIS = 49;
const S_CLOSEPARENTHESIS = 261;//')'; const S_CLOSEPARENTHESIS = 261;
const S_OPENBRACKET = 262;//'['; const S_OPENBRACKET = 262;
const S_CLOSEBRACKET = 263;//']'; const S_CLOSEBRACKET = 263;
const S_HYPHEN = 264;//'-'; const S_HYPHEN = 264;
const S_COLON = 265;//':'; const S_COLON = 265;
const S_DOUBLECOLON = 266;//'::'; const S_DOUBLECOLON = 266;
const S_SP = 267;//' '; const S_SP = 267;
const S_HTAB = 268;//"\t"; const S_HTAB = 268;
const S_CR = 269;//"\r"; const S_CR = 269;
const S_LF = 270;//"\n"; const S_LF = 270;
const S_IPV6TAG = 271;//'IPv6:'; const S_IPV6TAG = 271;
const S_LOWERTHAN = 272;//'<' const S_LOWERTHAN = 272;
const S_GREATERTHAN = 273;//'>' const S_GREATERTHAN = 273;
const S_COMMA = 274;//',' const S_COMMA = 274;
const S_SEMICOLON = 275;//';' const S_SEMICOLON = 275;
const S_OPENQBRACKET = 276;//'['; const S_OPENQBRACKET = 276;
const S_CLOSEQBRACKET = 277;//']'; const S_CLOSEQBRACKET = 277;
const S_EMPTY = null;//''; const S_EMPTY = null;
const GENERIC = 300; const GENERIC = 300;
const CRLF = 301; const CRLF = 301;
const INVALID = 302; const INVALID = 302;
+6 -9
View File
@@ -307,8 +307,6 @@ class EmailParser
/** /**
* validateQuotedPair * validateQuotedPair
*
* @TODO This needs to be reviewed
*/ */
private function validateQuotedPair() private function validateQuotedPair()
{ {
@@ -330,7 +328,6 @@ class EmailParser
throw new \InvalidArgumentException('ERR_DOT_START'); throw new \InvalidArgumentException('ERR_DOT_START');
} }
if ($this->lexer->token['type'] === EmailLexer::S_DQUOTE) { if ($this->lexer->token['type'] === EmailLexer::S_DQUOTE) {
//@TODO this can be improbed
if (!$closingQuote) { if (!$closingQuote) {
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) { if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT'); throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
@@ -344,7 +341,6 @@ class EmailParser
} }
} }
} }
//Comments
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->parseComments(); $this->parseComments();
} }
@@ -359,9 +355,9 @@ class EmailParser
} }
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) { if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
//if ($this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) { if ($this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) {
// $this->warnings[] = EmailValidator::DEPREC_QP; $this->warnings[] = EmailValidator::DEPREC_QP;
//} }
if ($this->lexer->isNextToken(EmailLexer::GENERIC)) { if ($this->lexer->isNextToken(EmailLexer::GENERIC)) {
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT'); throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
} }
@@ -447,9 +443,11 @@ class EmailParser
$this->lexer->token['type'] === EmailLexer::CRLF ) { $this->lexer->token['type'] === EmailLexer::CRLF ) {
throw new \InvalidArgumentException("ERR_FWS_CRLF_END"); throw new \InvalidArgumentException("ERR_FWS_CRLF_END");
} }
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $this->lexer->token['type'] !== EmailLexer::S_SP) {
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) {
throw new \InvalidArgumentException('ERR_EXPECTING_CTEXT'); throw new \InvalidArgumentException('ERR_EXPECTING_CTEXT');
} }
@@ -459,6 +457,5 @@ class EmailParser
} else { } else {
$this->warnings[] = EmailValidator::CFWS_FWS; $this->warnings[] = EmailValidator::CFWS_FWS;
} }
} }
} }
@@ -230,7 +230,6 @@ class EmailValidator
$this->warnings[] = self::RFC5321_TLD; $this->warnings[] = self::RFC5321_TLD;
} }
//@TODO review how to test TLD
//if (isset($this->atomList[self::COMPONENT_DOMAIN][$this->elementCount][0]) && //if (isset($this->atomList[self::COMPONENT_DOMAIN][$this->elementCount][0]) &&
// is_numeric($this->atomList[self::COMPONENT_DOMAIN][$this->elementCount][0]) // is_numeric($this->atomList[self::COMPONENT_DOMAIN][$this->elementCount][0])
//) { //) {
@@ -38,6 +38,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
array('example@faked(fake).co.uk'), array('example@faked(fake).co.uk'),
array('fabien+@symfony.com'), array('fabien+@symfony.com'),
array('инфо@письмо.рф'), array('инфо@письмо.рф'),
); );
} }
@@ -60,6 +61,8 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
array('ex\ample@localhost'), array('ex\ample@localhost'),
array('example@local\host'), array('example@local\host'),
array('example@localhost.'), array('example@localhost.'),
array('user name@example.com'),
array('username@ example . com'),
); );
} }