Domain back slash (#108)

* New home for all the tests. Fixed namespaces

* small code improvement

* Skipping tests failing only in Travis

* Add backslash as a forbbiden char
This commit is contained in:
Eduardo Gulias Davis
2016-05-15 11:55:36 +02:00
parent 4505d2060a
commit 313c7f9f3e
3 changed files with 11 additions and 4 deletions
+9 -4
View File
@@ -1,6 +1,5 @@
<?php
namespace Egulias\EmailValidator\Parser;
use Egulias\EmailValidator\EmailLexer;
@@ -133,9 +132,7 @@ class DomainPart extends Parser
do {
$prev = $this->lexer->getPrevious();
if ($this->lexer->token['type'] === EmailLexer::S_SLASH) {
throw new CharNotAllowed();
}
$this->checkNotAllowedChars($this->lexer->token);
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->parseComments();
@@ -173,6 +170,14 @@ class DomainPart extends Parser
return $domain;
}
private function checkNotAllowedChars($token)
{
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
if (isset($notAllowed[$token['type']])) {
throw new CharNotAllowed();
}
}
protected function parseDomainLiteral()
{
@@ -25,6 +25,7 @@ class MultipleValidationWithAnd implements EmailValidation
$result = true;
$errors = [];
foreach ($this->validations as $validation) {
$emailLexer->reset();
$result = $result && $validation->isValid($email, $emailLexer);
$this->warnings = array_merge($this->warnings, $validation->getWarnings());
$errors[] = $validation->getError();
@@ -127,6 +127,7 @@ class RFCValidationTest extends \PHPUnit_Framework_TestCase
['.example@localhost'],
['ex\ample@localhost'],
['example@local\host'],
['example@localhost\\'],
['example@localhost.'],
['user name@example.com'],
['username@ example . com'],