Skip to content

Commit

Permalink
Merge pull request #84 from egulias/82-brackets
Browse files Browse the repository at this point in the history
#82 orphan brackets
  • Loading branch information
egulias committed Nov 11, 2015
2 parents de448a3 + cc9defe commit 04c6cdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Egulias/EmailValidator/Parser/DomainPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ protected function doParseDomainPart()
{
$domain = '';
$openedParenthesis = 0;
$openBrackets = false;
do {
$prev = $this->lexer->getPrevious();

Expand Down Expand Up @@ -130,7 +131,7 @@ protected function doParseDomainPart()
$this->checkConsecutiveDots();
$this->checkDomainPartExceptions($prev);

if ($this->hasBrackets()) {
if ($openBrackets = $this->hasBrackets($openBrackets)) {
$this->parseDomainLiteral();
}

Expand Down Expand Up @@ -287,8 +288,12 @@ protected function checkDomainPartExceptions($prev)
}
}

protected function hasBrackets()
protected function hasBrackets($openBrackets)
{
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEBRACKET && !$openBrackets) {
throw new \InvalidArgumentException('ERR_EXPECTING_OPENBRACKET');
}

if ($this->lexer->token['type'] !== EmailLexer::S_OPENBRACKET) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/egulias/Tests/EmailValidator/EmailValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getValidEmails()
array('test@email^'),
array('test@email%'),
array('test@email$'),
array('[email protected]'),
);
}

Expand Down Expand Up @@ -123,6 +124,8 @@ public function getInvalidEmails()
array('test@email>'),
array('test@email<'),
array('test@email{'),
array('[email protected]]'),
array('test@ema[il.com'),
);
}

Expand Down

0 comments on commit 04c6cdf

Please sign in to comment.