[WIP] - Comments bug and comments improvemente

This commit is contained in:
Eduardo Gulias Davis
2014-07-03 00:55:00 +02:00
parent 679128b980
commit f7402dd8dc
3 changed files with 28 additions and 3 deletions
+1 -2
View File
@@ -33,7 +33,6 @@ abstract class Parser
$this->warnings[] = EmailValidator::DEPREC_QP;
}
/**
* @return string the the comment
* @throws \InvalidArgumentException
@@ -53,7 +52,7 @@ abstract class Parser
}
$this->lexer->moveNext();
if ($this->lexer->isNextToken(EmailLexer::GENERIC) || EmailLexer::S_EMPTY === $this->lexer->peek()) {
if ($this->lexer->isNextTokenAny(array(EmailLexer::GENERIC, EmailLexer::S_EMPTY))) {
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
}
@@ -26,7 +26,7 @@ class DomainPart extends Parser
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->warnings[] = EmailValidator::DEPREC_COMMENT;
$this->parseComments();
$this->parseDomainComments();
}
$domain = $this->doParseDomainPart();
@@ -275,4 +275,28 @@ class DomainPart extends Parser
$this->warnings[] = EmailValidator::RFC5322_LABEL_TOOLONG;
}
}
protected function parseDomainComments()
{
$this->isUnclosedComment();
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
$this->warnEscaping();
$this->lexer->moveNext();
}
$this->lexer->moveNext();
if ($this->lexer->isNextToken(EmailLexer::S_DOT)) {
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
}
}
protected function isUnclosedComment()
{
try {
$this->lexer->find(EmailLexer::S_CLOSEPARENTHESIS);
return true;
} catch (\RuntimeException $e) {
throw new \InvalidArgumentException('ERR_UNCLOSEDCOMMENT');
}
}
}
@@ -63,6 +63,8 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
array('example@localhost.'),
array('user name@example.com'),
array('username@ example . com'),
array('example@(fake).com'),
array('example@(fake.com'),
);
}