Added invalidtaion for backslash in domain literal and test data

This commit is contained in:
Eduardo Gulias Davis
2020-09-19 15:50:04 +02:00
parent b76c116718
commit 8405dcde01
5 changed files with 46 additions and 7 deletions
+4 -5
View File
@@ -17,6 +17,7 @@ use Egulias\EmailValidator\Warning\IPV6Deprecated;
use Egulias\EmailValidator\Warning\IPV6GroupCount;
use Egulias\EmailValidator\Warning\IPV6DoubleColon;
use Egulias\EmailValidator\Result\Reason\ExpectingDTEXT;
use Egulias\EmailValidator\Result\Reason\UnusualElements;
use Egulias\EmailValidator\Warning\DomainLiteral as WarningDomainLiteral;
class DomainLiteral extends Parser
@@ -51,10 +52,7 @@ class DomainLiteral extends Parser
}
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
$addressLiteral .= $this->lexer->token['value'];
$this->lexer->moveNext();
$this->validateQuotedPair();
return new InvalidEmail(new UnusualElements($this->lexer->token['value']), $this->lexer->token['value']);
}
if ($this->lexer->token['type'] === EmailLexer::S_IPV6TAG) {
$IPv6TAG = true;
@@ -190,7 +188,8 @@ class DomainLiteral extends Parser
{
if ($this->lexer->token['type'] === EmailLexer::INVALID ||
$this->lexer->token['type'] === EmailLexer::C_DEL ||
$this->lexer->token['type'] === EmailLexer::S_LF
$this->lexer->token['type'] === EmailLexer::S_LF ||
$this->lexer->token['type'] === EmailLexer::S_BACKSLASH
) {
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
}
+11 -1
View File
@@ -4,6 +4,16 @@ namespace Egulias\EmailValidator\Result\Reason;
class ExceptionFound implements Reason
{
/**
* @var \Exception
*/
private $exception;
public function __construct(\Exception $exception)
{
$this->exception = $exception;
}
public function code() : int
{
return 999;
@@ -11,6 +21,6 @@ class ExceptionFound implements Reason
public function description() : string
{
return 'An exception occurred during the execution';
return $this->exception->getMessage();
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace Egulias\EmailValidator\Result\Reason;
class UnusualElements implements Reason
{
/**
* @var string $element
*/
private $element = '';
public function __construct(string $element)
{
$this->element = $element;
}
public function code() : int
{
return 201;
}
public function description() : string
{
return 'Unusual element found, wourld render invalid in majority of cases. Element found: ' . $this->element;
}
}
+1 -1
View File
@@ -35,7 +35,7 @@ class RFCValidation implements EmailValidation
return false;
}
} catch (\Exception $invalid) {
$this->error = new InvalidEmail(new ExceptionFound(), '');
$this->error = new InvalidEmail(new ExceptionFound($invalid), '');
return false;
}
@@ -101,6 +101,9 @@ class RFCValidationTest extends TestCase
['test@email%'],
['test@email$'],
["1500111@профи-инвест.рф"],
['validipv6@[IPv6:2001:db8:1ff::a0b:dbd0]'],
['validipv4@[127.0.0.0]'],
['validipv4@127.0.0.0'],
);
}
@@ -170,6 +173,7 @@ class RFCValidationTest extends TestCase
['test@email{'],
['username@examp,le.com'],
['test@ '],
['validipv4@[127.\0.0.0]'],
];
}