From a2554975a42242877bf69be7eddf238754016819 Mon Sep 17 00:00:00 2001 From: Eduardo Gulias Davis Date: Wed, 11 May 2016 00:02:30 +0200 Subject: [PATCH] Changed invalid dns domains and backslash in domain --- .../EmailValidator/Parser/DomainPart.php | 12 +++++++++--- .../Tests/EmailValidator/EmailValidatorTest.php | 17 +++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Egulias/EmailValidator/Parser/DomainPart.php b/src/Egulias/EmailValidator/Parser/DomainPart.php index ba3a613..ab378c5 100644 --- a/src/Egulias/EmailValidator/Parser/DomainPart.php +++ b/src/Egulias/EmailValidator/Parser/DomainPart.php @@ -107,9 +107,7 @@ protected function doParseDomainPart() do { $prev = $this->lexer->getPrevious(); - if ($this->lexer->token['type'] === EmailLexer::S_SLASH) { - throw new \InvalidArgumentException('ERR_DOMAIN_CHAR_NOT_ALLOWED'); - } + $this->checkNotAllowedChars($this->lexer->token); if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { $this->parseComments(); @@ -148,6 +146,14 @@ protected function doParseDomainPart() return $domain; } + private function checkNotAllowedChars($token) + { + $notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true]; + if (isset($notAllowed[$token['type']])) { + throw new \InvalidArgumentException('ERR_DOMAIN_CHAR_NOT_ALLOWED'); + } + } + protected function parseDomainLiteral() { if ($this->lexer->isNextToken(EmailLexer::S_COLON)) { diff --git a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php index b95b0f9..d6af584 100644 --- a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php +++ b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php @@ -88,6 +88,7 @@ public function getInvalidEmails() array('.example@localhost'), array('ex\ample@localhost'), array('example@local\host'), + array('example@localhost\\'), array('example@localhost.'), array('user name@example.com'), array('username@ example . com'), @@ -201,21 +202,21 @@ public function getInvalidEmailsWithWarnings() EmailValidator::DEPREC_CFWS_NEAR_AT, EmailValidator::DNSWARN_NO_RECORD ), - 'example @example.co.uk' + 'example @invalid.example.com' ), array( array( EmailValidator::DEPREC_CFWS_NEAR_AT, EmailValidator::DNSWARN_NO_RECORD ), - 'example@ example.co.uk' + 'example@ invalid.example.com' ), array( array( EmailValidator::CFWS_COMMENT, EmailValidator::DNSWARN_NO_RECORD ), - 'example@example(examplecomment).co.uk' + 'example@invalid.example(examplecomment).com' ), array( array( @@ -223,7 +224,7 @@ public function getInvalidEmailsWithWarnings() EmailValidator::DEPREC_CFWS_NEAR_AT, EmailValidator::DNSWARN_NO_RECORD, ), - 'example(examplecomment)@example.co.uk' + 'example(examplecomment)@invalid.example.com' ), array( array( @@ -231,7 +232,7 @@ public function getInvalidEmailsWithWarnings() EmailValidator::CFWS_FWS, EmailValidator::DNSWARN_NO_RECORD, ), - "\"\t\"@example.co.uk" + "\"\t\"@invalid.example.com" ), array( array( @@ -239,7 +240,7 @@ public function getInvalidEmailsWithWarnings() EmailValidator::CFWS_FWS, EmailValidator::DNSWARN_NO_RECORD ), - "\"\r\"@example.co.uk" + "\"\r\"@invalid.example.com" ), array( array( @@ -331,14 +332,14 @@ public function getInvalidEmailsWithWarnings() EmailValidator::RFC5321_QUOTEDSTRING, EmailValidator::DNSWARN_NO_RECORD ), - '"example"@example.co.uk' + '"example"@invalid.example.com' ), 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' + 'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@invalid.example.com' ), array( array(