From 5fa792ad1853ae2bc60528dd3e5cbf4542d3c1df Mon Sep 17 00:00:00 2001 From: David Date: Sun, 1 Nov 2020 03:37:35 +0700 Subject: [PATCH] Email addresses with single quote should not be valid (#268) * 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 --- .travis.yml | 3 ++- src/EmailLexer.php | 2 ++ src/Parser/DomainPart.php | 1 + src/Validation/DNSCheckValidation.php | 2 +- tests/EmailValidator/EmailLexerTest.php | 1 + tests/EmailValidator/Validation/RFCValidationTest.php | 2 ++ 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 95a4687..8671074 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -42,3 +42,4 @@ script: after_script: - php vendor/bin/coveralls + diff --git a/src/EmailLexer.php b/src/EmailLexer.php index cb47c01..daa98fe 100644 --- a/src/EmailLexer.php +++ b/src/EmailLexer.php @@ -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; @@ -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, diff --git a/src/Parser/DomainPart.php b/src/Parser/DomainPart.php index 8dba7f1..f40bacc 100644 --- a/src/Parser/DomainPart.php +++ b/src/Parser/DomainPart.php @@ -335,6 +335,7 @@ class DomainPart extends Parser { $invalidDomainTokens = array( EmailLexer::S_DQUOTE => true, + EmailLexer::S_SQUOTE => true, EmailLexer::S_SEMICOLON => true, EmailLexer::S_GREATERTHAN => true, EmailLexer::S_LOWERTHAN => true, diff --git a/src/Validation/DNSCheckValidation.php b/src/Validation/DNSCheckValidation.php index 80b3b3f..491082a 100644 --- a/src/Validation/DNSCheckValidation.php +++ b/src/Validation/DNSCheckValidation.php @@ -120,7 +120,7 @@ class DNSCheckValidation implements EmailValidation // No MX, A or AAAA DNS records - if (empty($dnsRecords) || !$dnsRecords) { + if (empty($dnsRecords)) { $this->error = new NoDNSRecord(); return false; } diff --git a/tests/EmailValidator/EmailLexerTest.php b/tests/EmailValidator/EmailLexerTest.php index 3d8bc86..7805092 100644 --- a/tests/EmailValidator/EmailLexerTest.php +++ b/tests/EmailValidator/EmailLexerTest.php @@ -138,6 +138,7 @@ class EmailLexerTests extends TestCase 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), diff --git a/tests/EmailValidator/Validation/RFCValidationTest.php b/tests/EmailValidator/Validation/RFCValidationTest.php index 6a56ef3..25a0146 100644 --- a/tests/EmailValidator/Validation/RFCValidationTest.php +++ b/tests/EmailValidator/Validation/RFCValidationTest.php @@ -168,6 +168,7 @@ class RFCValidationTest extends TestCase ['test@email{'], ['test@ '], ['test@example.com []'], + ["test@example.com'"], ]; } @@ -212,6 +213,7 @@ class RFCValidationTest extends TestCase [new CRNoLF(), "example@exa\rmple.co.uk"], [new CRNoLF(), "example@[\r]"], [new CRNoLF(), "exam\rple@example.co.uk"], + [new ExpectingATEXT(), "test@example.com'"], ]; }