Skip to content

Commit

Permalink
Email addresses with single quote should not be valid (#268)
Browse files Browse the repository at this point in the history
* Fixes issue for email addresses with single quote in domain part
* specify version in cli for older php versions

Co-authored-by: Eduardo Gulias Davis <eduardomgulias@gmail.com>
  • Loading branch information
davpsh and egulias committed Oct 31, 2020
1 parent 68e418e commit 5fa792a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ matrix:

install:
- if [ "$deps" = "low" ]; then composer update --prefer-lowest; else composer install; fi
- if [ "$psalm" = "yes" ]; then composer require --dev vimeo/psalm; fi
- if [ "$psalm" = "yes" ]; then composer require --dev vimeo/psalm:3.18.2; fi

before_script:
- mkdir -p build/logs
Expand All @@ -42,3 +42,4 @@ script:

after_script:
- php vendor/bin/coveralls

2 changes: 2 additions & 0 deletions src/EmailLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class EmailLexer extends AbstractLexer
const S_BACKSLASH = 92;
const S_DOT = 46;
const S_DQUOTE = 34;
const S_SQUOTE = 39;
const S_OPENPARENTHESIS = 49;
const S_CLOSEPARENTHESIS = 261;
const S_OPENBRACKET = 262;
Expand Down Expand Up @@ -58,6 +59,7 @@ class EmailLexer extends AbstractLexer
'/' => self::S_SLASH,
',' => self::S_COMMA,
'.' => self::S_DOT,
"'" => self::S_SQUOTE,
'"' => self::S_DQUOTE,
'-' => self::S_HYPHEN,
'::' => self::S_DOUBLECOLON,
Expand Down
1 change: 1 addition & 0 deletions src/Parser/DomainPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ protected function checkDomainPartExceptions(array $prev)
{
$invalidDomainTokens = array(
EmailLexer::S_DQUOTE => true,
EmailLexer::S_SQUOTE => true,
EmailLexer::S_SEMICOLON => true,
EmailLexer::S_GREATERTHAN => true,
EmailLexer::S_LOWERTHAN => true,
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/DNSCheckValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function validateDnsRecords($host)


// No MX, A or AAAA DNS records
if (empty($dnsRecords) || !$dnsRecords) {
if (empty($dnsRecords)) {
$this->error = new NoDNSRecord();
return false;
}
Expand Down
1 change: 1 addition & 0 deletions tests/EmailValidator/EmailLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function getTokens()
array(":", EmailLexer::S_COLON),
array(".", EmailLexer::S_DOT),
array("\"", EmailLexer::S_DQUOTE),
array("'", EmailLexer::S_SQUOTE),
array("-", EmailLexer::S_HYPHEN),
array("\\", EmailLexer::S_BACKSLASH),
array("/", EmailLexer::S_SLASH),
Expand Down
2 changes: 2 additions & 0 deletions tests/EmailValidator/Validation/RFCValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public function getInvalidEmails()
['test@email{'],
['test@ '],
['test@example.com []'],
["test@example.com'"],
];
}

Expand Down Expand Up @@ -212,6 +213,7 @@ public function getInvalidEmailsWithErrors()
[new CRNoLF(), "example@exa\rmple.co.uk"],
[new CRNoLF(), "example@[\r]"],
[new CRNoLF(), "exam\rple@example.co.uk"],
[new ExpectingATEXT(), "test@example.com'"],
];
}

Expand Down

0 comments on commit 5fa792a

Please sign in to comment.