Dot at the end

This commit is contained in:
Eduardo Gulias Davis
2015-06-25 22:00:09 +02:00
parent 1cead9fa77
commit f69cd9e42f
5 changed files with 18 additions and 6 deletions
@@ -11,8 +11,6 @@ use Egulias\EmailValidator\InvalidEmail;
*/
class EmailValidator
{
const ERR_BACKSLASHEND = 140;
const ERR_DOT_END = 142;
const ERR_DOMAINHYPHENSTART = 143;
const ERR_DOMAINHYPHENEND = 144;
const ERR_UNCLOSEDQUOTEDSTR = 145;
@@ -0,0 +1,11 @@
<?php
namespace Egulias\EmailValidator\Exception;
use Egulias\EmailValidator\InvalidEmail;
class DotAtEnd extends InvalidEmail
{
const CODE = 142;
const REASON = "Dot at the end";
}
@@ -5,6 +5,7 @@ namespace Egulias\EmailValidator\Parser;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Exception\ConsecutiveAt;
use Egulias\EmailValidator\Exception\DotAtEnd;
use Egulias\EmailValidator\Exception\DotAtStart;
use Egulias\EmailValidator\Exception\ExpectedQPair;
use Egulias\EmailValidator\Exception\ExpectingATEXT;
@@ -44,7 +45,7 @@ class DomainPart extends Parser
$length = strlen($domain);
if ($prev['type'] === EmailLexer::S_DOT) {
throw new \InvalidArgumentException('ERR_DOT_END');
throw new DotAtEnd();
}
if ($prev['type'] === EmailLexer::S_HYPHEN) {
throw new \InvalidArgumentException('ERR_DOMAINHYPHENEND');
@@ -2,6 +2,7 @@
namespace Egulias\EmailValidator\Parser;
use Egulias\EmailValidator\Exception\DotAtEnd;
use Egulias\EmailValidator\Exception\DotAtStart;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\EmailValidator;
@@ -36,7 +37,7 @@ class LocalPart extends Parser
$this->lexer->token['type'] === EmailLexer::S_DOT &&
$this->lexer->isNextToken(EmailLexer::S_AT)
) {
throw new \InvalidArgumentException('ERR_DOT_END');
throw new DotAtEnd();
}
$this->warnEscaping();
@@ -6,6 +6,7 @@ use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Exception\AtextAfterCFWS;
use Egulias\EmailValidator\Exception\ConsecutiveAt;
use Egulias\EmailValidator\Exception\ConsecutiveDot;
use Egulias\EmailValidator\Exception\DotAtEnd;
use Egulias\EmailValidator\Exception\DotAtStart;
use Egulias\EmailValidator\Exception\ExpectingATEXT;
use Egulias\EmailValidator\Exception\ExpectingDTEXT;
@@ -157,8 +158,8 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
array(ExpectingATEXT::CODE, '<fabien_potencier>@example.fr'),
array(DotAtStart::CODE, '.example@localhost'),
array(DotAtStart::CODE, 'example@.localhost'),
array(EmailValidator::ERR_DOT_END, 'example@localhost.'),
array(EmailValidator::ERR_DOT_END, 'example.@example.co.uk'),
array(DotAtEnd::CODE, 'example@localhost.'),
array(DotAtEnd::CODE, 'example.@example.co.uk'),
array(EmailValidator::ERR_UNCLOSEDCOMMENT, '(example@localhost'),
array(EmailValidator::ERR_UNCLOSEDQUOTEDSTR, '"example@localhost'),
array(ExpectingATEXT::CODE, 'exa"mple@localhost'),