Changed invalid dns domains and backslash in domain (#107)

Fixes #91 and #74 for v1.2.x
This commit is contained in:
Eduardo Gulias Davis
2016-05-15 01:10:54 +02:00
parent afc6adc0b9
commit f463fbe542
5 changed files with 188 additions and 603 deletions
+5 -6
View File
@@ -12,15 +12,17 @@ php:
env:
global:
- deps=no
- deps=high
matrix:
fast_finish: true
include:
- php: 5.3
env: deps=low
- php: 5.6
env: deps=high
- php: 5.4
env: deps=no
- php: 5.5
env: deps=no
install:
- if [ "$deps" = "no" ]; then composer install; fi
@@ -31,6 +33,3 @@ script:
- mkdir -p build/logs
- phpunit --coverage-clover build/logs/clover.xml
after_script:
- php vendor/bin/coveralls
+2 -3
View File
@@ -15,11 +15,10 @@
},
"require": {
"php": ">= 5.3.3",
"doctrine/lexer": "~1.0,>=1.0.1"
"doctrine/lexer": "1.0.1"
},
"require-dev" : {
"satooshi/php-coveralls": "dev-master",
"phpunit/phpunit": "~4.4"
"phpunit/phpunit": "4.8.24"
},
"autoload": {
"psr-0": {
Generated
+163 -583
View File
File diff suppressed because it is too large Load Diff
@@ -107,9 +107,7 @@ class DomainPart extends Parser
do {
$prev = $this->lexer->getPrevious();
if ($this->lexer->token['type'] === EmailLexer::S_SLASH) {
throw new \InvalidArgumentException('ERR_DOMAIN_CHAR_NOT_ALLOWED');
}
$this->checkNotAllowedChars($this->lexer->token);
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->parseComments();
@@ -148,6 +146,14 @@ class DomainPart extends Parser
return $domain;
}
private function checkNotAllowedChars($token)
{
$notAllowed = array(EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true);
if (isset($notAllowed[$token['type']])) {
throw new \InvalidArgumentException('ERR_DOMAIN_CHAR_NOT_ALLOWED');
}
}
protected function parseDomainLiteral()
{
if ($this->lexer->isNextToken(EmailLexer::S_COLON)) {
@@ -88,6 +88,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
array('.example@localhost'),
array('ex\ample@localhost'),
array('example@local\host'),
array('example@localhost\\'),
array('example@localhost.'),
array('user name@example.com'),
array('username@ example . com'),
@@ -201,21 +202,21 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
EmailValidator::DEPREC_CFWS_NEAR_AT,
EmailValidator::DNSWARN_NO_RECORD
),
'example @example.co.uk'
'example @invalid.example.com'
),
array(
array(
EmailValidator::DEPREC_CFWS_NEAR_AT,
EmailValidator::DNSWARN_NO_RECORD
),
'example@ example.co.uk'
'example@ invalid.example.com'
),
array(
array(
EmailValidator::CFWS_COMMENT,
EmailValidator::DNSWARN_NO_RECORD
),
'example@example(examplecomment).co.uk'
'example@invalid.example(examplecomment).com'
),
array(
array(
@@ -223,7 +224,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
EmailValidator::DEPREC_CFWS_NEAR_AT,
EmailValidator::DNSWARN_NO_RECORD,
),
'example(examplecomment)@example.co.uk'
'example(examplecomment)@invalid.example.com'
),
array(
array(
@@ -231,7 +232,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
EmailValidator::CFWS_FWS,
EmailValidator::DNSWARN_NO_RECORD,
),
"\"\t\"@example.co.uk"
"\"\t\"@invalid.example.com"
),
array(
array(
@@ -239,7 +240,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
EmailValidator::CFWS_FWS,
EmailValidator::DNSWARN_NO_RECORD
),
"\"\r\"@example.co.uk"
"\"\r\"@invalid.example.com"
),
array(
array(
@@ -331,14 +332,14 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
EmailValidator::RFC5321_QUOTEDSTRING,
EmailValidator::DNSWARN_NO_RECORD
),
'"example"@example.co.uk'
'"example"@invalid.example.com'
),
array(
array(
EmailValidator::RFC5322_LOCAL_TOOLONG,
EmailValidator::DNSWARN_NO_RECORD
),
'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@example.co.uk'
'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@invalid.example.com'
),
array(
array(