mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-31 12:40:28 +00:00
Concecutive dots and invalid token
This commit is contained in:
@@ -8,11 +8,28 @@ use Egulias\EmailValidator\Result\ValidEmail;
|
||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
||||
use Egulias\EmailValidator\Warning\LocalTooLong;
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Result\Reason\ConsecutiveDot;
|
||||
use Egulias\EmailValidator\Result\Reason\DotAtEnd;
|
||||
use Egulias\EmailValidator\Result\Reason\DotAtStart;
|
||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT as ReasonExpectingATEXT;
|
||||
|
||||
class LocalPart extends Parser
|
||||
{
|
||||
|
||||
/*
|
||||
@property array
|
||||
*/
|
||||
private $invalidTokens = array(
|
||||
EmailLexer::S_COMMA => EmailLexer::S_COMMA,
|
||||
EmailLexer::S_CLOSEBRACKET => EmailLexer::S_CLOSEBRACKET,
|
||||
EmailLexer::S_OPENBRACKET => EmailLexer::S_OPENBRACKET,
|
||||
EmailLexer::S_GREATERTHAN => EmailLexer::S_GREATERTHAN,
|
||||
EmailLexer::S_LOWERTHAN => EmailLexer::S_LOWERTHAN,
|
||||
EmailLexer::S_COLON => EmailLexer::S_COLON,
|
||||
EmailLexer::S_SEMICOLON => EmailLexer::S_SEMICOLON,
|
||||
EmailLexer::INVALID => EmailLexer::INVALID
|
||||
);
|
||||
|
||||
public function parse($localPart) : Result
|
||||
{
|
||||
$closingQuote = false;
|
||||
@@ -45,7 +62,9 @@ class LocalPart extends Parser
|
||||
}
|
||||
}
|
||||
|
||||
$this->checkConsecutiveDots();
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']);
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT &&
|
||||
$this->lexer->isNextToken(EmailLexer::S_AT)
|
||||
@@ -53,13 +72,14 @@ class LocalPart extends Parser
|
||||
return new InvalidEmail(new DotAtEnd(), $this->lexer->token['value']);
|
||||
}
|
||||
|
||||
//$this->warnEscaping();
|
||||
$resultEscaping = $this->validateEscaping();
|
||||
if ($resultEscaping->isInvalid()) {
|
||||
return $resultEscaping;
|
||||
}
|
||||
|
||||
$this->isInvalidToken($this->lexer->token, $closingQuote);
|
||||
if (isset($this->invalidTokens[$this->lexer->token['type']])) {
|
||||
return new InvalidEmail(new ReasonExpectingATEXT('Invalid token found'), $this->lexer->token['value']);
|
||||
}
|
||||
|
||||
if ($this->isFWS()) {
|
||||
$this->parseFWS();
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Result\Reason;
|
||||
|
||||
class ConsecutiveDot implements Reason
|
||||
{
|
||||
public function code() : int
|
||||
{
|
||||
return 132;
|
||||
}
|
||||
|
||||
public function description() : string
|
||||
{
|
||||
return 'Concecutive DOT found';
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ use Egulias\EmailValidator\Exception\ExpectingDTEXT;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
use Egulias\EmailValidator\Exception\UnclosedComment;
|
||||
use Egulias\EmailValidator\Exception\UnopenedComment as ExceptionUnopenedComment;
|
||||
use Egulias\EmailValidator\Result\Reason\ConsecutiveDot as ReasonConsecutiveDot;
|
||||
use Egulias\EmailValidator\Result\Reason\DotAtEnd as ReasonDotAtEnd;
|
||||
use Egulias\EmailValidator\Result\Reason\NoLocalPart;
|
||||
use Egulias\EmailValidator\Result\Reason\UnOpenedComment;
|
||||
@@ -194,9 +195,9 @@ class RFCValidationTest extends TestCase
|
||||
[new DomainHyphened(), 'example@example-.co.uk'],
|
||||
[new DomainHyphened(), 'example@example-'],
|
||||
[new ConsecutiveAt(), 'example@@example.co.uk'],
|
||||
[new ConsecutiveDot(), 'example..example@example.co.uk'],
|
||||
[new InvalidEmail(new ReasonConsecutiveDot(), '.'), 'example..example@example.co.uk'],
|
||||
[new ConsecutiveDot(), 'example@example..co.uk'],
|
||||
[new ExpectingATEXT(), '<example_example>@example.fr'],
|
||||
[new InvalidEmail(new ReasonExpectingATEXT('Invalid token found'), '<'), '<example_example>@example.fr'],
|
||||
[new InvalidEmail(new ReasonDotAtStart(), '.'), '.example@localhost'],
|
||||
[new DotAtStart(), 'example@.localhost'],
|
||||
[new DotAtEnd(), 'example@localhost.'],
|
||||
|
||||
Reference in New Issue
Block a user