new escaping check

This commit is contained in:
Eduardo Gulias Davis
2020-05-15 23:25:03 +02:00
parent 7e0ee1686d
commit 2ea18ea9ba
2 changed files with 33 additions and 1 deletions
+6 -1
View File
@@ -53,7 +53,12 @@ class LocalPart extends Parser
return new InvalidEmail(new DotAtEnd(), $this->lexer->token['value']);
}
$this->warnEscaping();
//$this->warnEscaping();
$resultEscaping = $this->validateEscaping();
if (!$resultEscaping->isValid()) {
return $resultEscaping;
}
$this->isInvalidToken($this->lexer->token, $closingQuote);
if ($this->isFWS()) {
+27
View File
@@ -12,6 +12,10 @@ use Egulias\EmailValidator\Exception\ExpectingQPair;
use Egulias\EmailValidator\Exception\ExpectingATEXT;
use Egulias\EmailValidator\Exception\ExpectingCTEXT;
use Egulias\EmailValidator\Exception\UnclosedComment;
use Egulias\EmailValidator\Result\InvalidEmail;
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT as ReasonExpectingATEXT;
use Egulias\EmailValidator\Result\Result;
use Egulias\EmailValidator\Result\ValidEmail;
use Egulias\EmailValidator\Warning\CFWSNearAt;
use Egulias\EmailValidator\Warning\CFWSWithFWS;
use Egulias\EmailValidator\Warning\Comment;
@@ -183,6 +187,7 @@ abstract class Parser
*/
protected function warnEscaping() : bool
{
//Backslash found
if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) {
return false;
}
@@ -201,6 +206,28 @@ abstract class Parser
}
protected function validateEscaping() : Result
{
//Backslash found
if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) {
return new ValidEmail();
}
if ($this->lexer->isNextToken(EmailLexer::GENERIC)) {
return new InvalidEmail(new ReasonExpectingATEXT('Found ATOM after escaping'), $this->lexer->token['value']);
}
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) {
return new ValidEmail();
}
$this->warnings[QuotedPart::CODE] =
new QuotedPart($this->lexer->getPrevious()['type'], $this->lexer->token['type']);
return new ValidEmail();
}
protected function checkCRLFInFWS()
{
if ($this->lexer->token['type'] !== EmailLexer::CRLF) {