From 82f8514d893084f87ea676cfe3561770b3e4e2fc Mon Sep 17 00:00:00 2001 From: Eduardo Gulias Davis Date: Fri, 22 Aug 2014 01:05:58 +0200 Subject: [PATCH] COMMA is not allowed in domain part --- src/Egulias/EmailValidator/EmailLexer.php | 8 ++++---- src/Egulias/EmailValidator/Parser/DomainPart.php | 6 ++++++ tests/egulias/Tests/EmailValidator/EmailValidatorTest.php | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Egulias/EmailValidator/EmailLexer.php b/src/Egulias/EmailValidator/EmailLexer.php index 2066f7c..3d5cd69 100644 --- a/src/Egulias/EmailValidator/EmailLexer.php +++ b/src/Egulias/EmailValidator/EmailLexer.php @@ -116,13 +116,13 @@ public function moveNext() protected function getCatchablePatterns() { return array( - '[a-zA-Z_]+[4,6]?', + '[a-zA-Z_]+[46]?', '[0-9]+', '\r\n', '::', '\s+', - '[\x1-\x1F]+', - '.' + '[\x10-\x1F]+', + '.', ); } @@ -149,7 +149,7 @@ protected function getType(&$value) return $this->charValue[$value]; } - if (preg_match('/[\x1-\x1F]+/', $value)) { + if (preg_match('/[\x10-\x1F]+/', $value)) { return self::INVALID; } diff --git a/src/Egulias/EmailValidator/Parser/DomainPart.php b/src/Egulias/EmailValidator/Parser/DomainPart.php index ce3756c..d622b94 100644 --- a/src/Egulias/EmailValidator/Parser/DomainPart.php +++ b/src/Egulias/EmailValidator/Parser/DomainPart.php @@ -235,12 +235,18 @@ protected function checkIPV4Tag($addressLiteral) protected function checkDomainPartExceptions($prev) { + if ($this->lexer->token['type'] === EmailLexer::S_COMMA) { + throw new \InvalidArgumentException('ERR_COMMA_IN_DOMAIN'); + } + if ($this->lexer->token['type'] === EmailLexer::S_AT) { throw new \InvalidArgumentException('ERR_CONSECUTIVEATS'); } + if ($this->lexer->token['type'] === EmailLexer::S_OPENQBRACKET && $prev['type'] !== EmailLexer::S_AT) { throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT'); } + if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) { throw new \InvalidArgumentException('ERR_DOMAINHYPHENEND'); } diff --git a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php index 348d4d2..c279157 100644 --- a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php +++ b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php @@ -45,7 +45,7 @@ public function getValidEmails() /** * @dataProvider getInvalidEmails */ - public function testAInvalidEmails($email) + public function testInvalidEmails($email) { $this->assertFalse($this->validator->isValid($email)); } @@ -65,6 +65,7 @@ public function getInvalidEmails() array('username@ example . com'), array('example@(fake).com'), array('example@(fake.com'), + array('username@example,com'), ); }