Merge pull request #84 from egulias/82-brackets

#82 orphan brackets
This commit is contained in:
Eduardo Gulias Davis
2015-11-11 04:28:32 +01:00
2 changed files with 10 additions and 2 deletions
@@ -103,6 +103,7 @@ class DomainPart extends Parser
{
$domain = '';
$openedParenthesis = 0;
$openBrackets = false;
do {
$prev = $this->lexer->getPrevious();
@@ -130,7 +131,7 @@ class DomainPart extends Parser
$this->checkConsecutiveDots();
$this->checkDomainPartExceptions($prev);
if ($this->hasBrackets()) {
if ($openBrackets = $this->hasBrackets($openBrackets)) {
$this->parseDomainLiteral();
}
@@ -287,8 +288,12 @@ class DomainPart extends Parser
}
}
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;
}
@@ -63,6 +63,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
array('test@email^'),
array('test@email%'),
array('test@email$'),
array('test@email.com.au'),
);
}
@@ -123,6 +124,8 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
array('test@email>'),
array('test@email<'),
array('test@email{'),
array('test@email.com]'),
array('test@ema[il.com'),
);
}