mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-25 05:58:25 +00:00
replacing exceptions
This commit is contained in:
@@ -4,7 +4,6 @@ namespace Egulias\EmailValidator\Parser;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\CommaInDomain;
|
||||
use Egulias\EmailValidator\Exception\ConsecutiveAt;
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
||||
use Egulias\EmailValidator\Result\Reason\CharNotAllowed as ReasonCharNotAllowed;
|
||||
@@ -145,10 +144,13 @@ class DomainPart extends Parser
|
||||
}
|
||||
}
|
||||
|
||||
$this->checkConsecutiveDots();
|
||||
$result = $this->checkDomainPartExceptions($prev);
|
||||
if ($result->isInvalid()) {
|
||||
return $result;
|
||||
$dotsResult = $this->checkConsecutiveDots();
|
||||
if ($dotsResult) {
|
||||
return $dotsResult;
|
||||
}
|
||||
$exceptionsResult = $this->checkDomainPartExceptions($prev);
|
||||
if ($exceptionsResult->isInvalid()) {
|
||||
return $exceptionsResult;
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENBRACKET) {
|
||||
@@ -162,7 +164,10 @@ class DomainPart extends Parser
|
||||
$this->checkLabelLength($prev);
|
||||
|
||||
if ($this->isFWS()) {
|
||||
$this->parseFWS();
|
||||
$FwsResult = $this->parseFWS();
|
||||
if($FwsResult->isInvalid()) {
|
||||
return $FwsResult;
|
||||
}
|
||||
}
|
||||
|
||||
$domain .= $this->lexer->token['value'];
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
namespace Egulias\EmailValidator\Parser;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\ConsecutiveDot;
|
||||
use Egulias\EmailValidator\Exception\CRLFAtTheEnd;
|
||||
use Egulias\EmailValidator\Exception\CRLFX2;
|
||||
use Egulias\EmailValidator\Exception\ExpectingQPair;
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Exception\UnclosedComment;
|
||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
||||
use Egulias\EmailValidator\Result\Reason\ConsecutiveAt;
|
||||
use Egulias\EmailValidator\Result\Reason\ConsecutiveDot;
|
||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT as ReasonExpectingATEXT;
|
||||
use Egulias\EmailValidator\Result\Result;
|
||||
use Egulias\EmailValidator\Result\ValidEmail;
|
||||
@@ -112,16 +113,16 @@ abstract class Parser
|
||||
{
|
||||
$foldingWS = new FoldingWhiteSpace($this->lexer);
|
||||
$resultFWS = $foldingWS->parse('remove');
|
||||
if ($resultFWS->isValid()) {
|
||||
//if ($resultFWS->isValid()) {
|
||||
$this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
|
||||
}
|
||||
//}
|
||||
return $resultFWS;
|
||||
}
|
||||
|
||||
protected function checkConsecutiveDots()
|
||||
{
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
throw new ConsecutiveDot();
|
||||
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ use Egulias\EmailValidator\Warning\AddressLiteral;
|
||||
use Egulias\EmailValidator\Warning\IPV6ColonStart;
|
||||
use Egulias\EmailValidator\Warning\IPV6Deprecated;
|
||||
use Egulias\EmailValidator\Warning\IPV6GroupCount;
|
||||
use Egulias\EmailValidator\Exception\ConsecutiveAt;
|
||||
use Egulias\EmailValidator\Warning\IPV6DoubleColon;
|
||||
use Egulias\EmailValidator\Exception\ConsecutiveDot;
|
||||
use Egulias\EmailValidator\Exception\ExpectingDTEXT;
|
||||
@@ -189,11 +188,11 @@ class RFCValidationTest extends TestCase
|
||||
[new InvalidEmail(new NoLocalPart(), "@"), '@example.co.uk'],
|
||||
[new InvalidEmail(new ReasonNoDomainPart(), ''), 'example@'],
|
||||
[new InvalidEmail(new ReasonDomainHyphened('Hypen found near DOT'), '-'), 'example@example-.co.uk'],
|
||||
[new CRNoLF(), "example@example\r.com"],
|
||||
[new InvalidEmail(new ReasonCRNoLF(), "\r"), "example@example\r.com"],
|
||||
[new InvalidEmail(new ReasonDomainHyphened('Hypen found at the end of the domain'), '-'), 'example@example-'],
|
||||
[new InvalidEmail(new ReasonConsecutiveAt(), '@'), 'example@@example.co.uk'],
|
||||
[new InvalidEmail(new ReasonConsecutiveDot(), '.'), 'example..example@example.co.uk'],
|
||||
[new ConsecutiveDot(), 'example@example..co.uk'],
|
||||
[new InvalidEmail(new ReasonConsecutiveDot(), '.'), 'example@example..co.uk'],
|
||||
[new InvalidEmail(new ReasonExpectingATEXT('Invalid token found'), '<'), '<example_example>@example.fr'],
|
||||
[new InvalidEmail(new ReasonDotAtStart(), '.'), '.example@localhost'],
|
||||
[new InvalidEmail(new ReasonDotAtStart(), '.'), 'example@.localhost'],
|
||||
|
||||
Reference in New Issue
Block a user