Skip to content

Commit

Permalink
Changed invalid dns domains and backslash in domain
Browse files Browse the repository at this point in the history
  • Loading branch information
egulias committed May 10, 2016
1 parent afc6adc commit a255497
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
12 changes: 9 additions & 3 deletions src/Egulias/EmailValidator/Parser/DomainPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
17 changes: 9 additions & 8 deletions tests/egulias/Tests/EmailValidator/EmailValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]'),
array('username@ example . com'),
Expand Down Expand Up @@ -201,45 +202,45 @@ 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(
EmailValidator::CFWS_COMMENT,
EmailValidator::DEPREC_CFWS_NEAR_AT,
EmailValidator::DNSWARN_NO_RECORD,
),
'example(examplecomment)@example.co.uk'
'example(examplecomment)@invalid.example.com'
),
array(
array(
EmailValidator::RFC5321_QUOTEDSTRING,
EmailValidator::CFWS_FWS,
EmailValidator::DNSWARN_NO_RECORD,
),
"\"\t\"@example.co.uk"
"\"\t\"@invalid.example.com"
),
array(
array(
EmailValidator::RFC5321_QUOTEDSTRING,
EmailValidator::CFWS_FWS,
EmailValidator::DNSWARN_NO_RECORD
),
"\"\r\"@example.co.uk"
"\"\r\"@invalid.example.com"
),
array(
array(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a255497

Please sign in to comment.