From cdd1840217cb4fdff70b376eecd1a6b3b429fb28 Mon Sep 17 00:00:00 2001 From: m Date: Sun, 1 Apr 2018 19:29:32 +0200 Subject: [PATCH 1/4] =?UTF-8?q?correction=20:=20filtre=20adresse=20e-mail?= =?UTF-8?q?=20avec=20nom=20de=20domaine=20internationalis=C3=A9=20https://?= =?UTF-8?q?framagit.org/framasoft/framadate/issues/233?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Framadate/Services/InputService.php | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/classes/Framadate/Services/InputService.php b/app/classes/Framadate/Services/InputService.php index 2c5e1da..32283b1 100644 --- a/app/classes/Framadate/Services/InputService.php +++ b/app/classes/Framadate/Services/InputService.php @@ -65,7 +65,45 @@ class InputService { } public function filterMail($mail) { - return filter_var($mail, FILTER_VALIDATE_EMAIL); + + $mail = mb_strtolower(trim($mail)); + + + $decoupage = explode("@", $mail, 2); + + $resultat = FALSE; + + + if (isset($decoupage[1])) { + + $domaine = idn_to_ascii( + $decoupage[1] + , IDNA_DEFAULT + , INTL_IDNA_VARIANT_UTS46 + ); + + $adresseConvertie = "{$decoupage[0]}@$domaine"; + + $adresseFiltree = filter_var( + $adresseConvertie + , FILTER_VALIDATE_EMAIL + , ["flags" => FILTER_FLAG_EMAIL_UNICODE] // permet d'utiliser des accents avant le @ + ); + + if ($adresseConvertie === $adresseFiltree) { + + $testMX = getmxrr($domaine, $_); // tester sur le domaine indique un serveur MX + + if ($testMX) { + $resultat = $mail; + } + + } + + } + + + return $resultat; } public function filterDescription($description) { From 1d8244fd99ff84935fa4b843d745f03a348594e7 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Tue, 3 Apr 2018 12:30:37 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=20correction=20:=20filtre=20adresse=20e-ma?= =?UTF-8?q?il=20avec=20nom=20de=20domaine=20internationalis=C3=A9=20=20htt?= =?UTF-8?q?ps://framagit.org/framasoft/framadate/merge=5Frequests/268?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Framadate/Services/InputService.php | 42 ++--- composer.json | 3 +- composer.lock | 167 ++++++++++++------ 3 files changed, 127 insertions(+), 85 deletions(-) diff --git a/app/classes/Framadate/Services/InputService.php b/app/classes/Framadate/Services/InputService.php index 32283b1..5f30885 100644 --- a/app/classes/Framadate/Services/InputService.php +++ b/app/classes/Framadate/Services/InputService.php @@ -18,6 +18,8 @@ */ namespace Framadate\Services; use DateTime; +use Egulias\EmailValidator\EmailValidator; +use Egulias\EmailValidator\Validation\RFCValidation; /** * This class helps to clean all inputs from the users or external services. @@ -66,42 +68,24 @@ class InputService { public function filterMail($mail) { - $mail = mb_strtolower(trim($mail)); + /////////////////////////////////////////////////////////////////////////////////////// + // formatting + $mail = trim($mail); - $decoupage = explode("@", $mail, 2); + /////////////////////////////////////////////////////////////////////////////////////// + // e-mail validation $resultat = FALSE; - - if (isset($decoupage[1])) { - - $domaine = idn_to_ascii( - $decoupage[1] - , IDNA_DEFAULT - , INTL_IDNA_VARIANT_UTS46 - ); - - $adresseConvertie = "{$decoupage[0]}@$domaine"; - - $adresseFiltree = filter_var( - $adresseConvertie - , FILTER_VALIDATE_EMAIL - , ["flags" => FILTER_FLAG_EMAIL_UNICODE] // permet d'utiliser des accents avant le @ - ); - - if ($adresseConvertie === $adresseFiltree) { - - $testMX = getmxrr($domaine, $_); // tester sur le domaine indique un serveur MX - - if ($testMX) { - $resultat = $mail; - } - - } - + $validator = new EmailValidator(); + + if ($validator->isValid($mail, new RFCValidation())) { + $resultat = $mail; } + /////////////////////////////////////////////////////////////////////////////////////// + // return return $resultat; } diff --git a/composer.json b/composer.json index f48c4aa..d19901f 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,8 @@ "phpmailer/phpmailer": "^5.2", "ircmaxell/password-compat": "dev-master", "roave/security-advisories": "dev-master", - "erusev/parsedown": "^1.7" + "erusev/parsedown": "^1.7", + "egulias/email-validator": "~2.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 6e33e0f..e855b8c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,119 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "a3ca2dd4f87562095f8c19a94560fed7", + "content-hash": "40759eac537218b0212ed923261b9850", "packages": [ + { + "name": "doctrine/lexer", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09T13:34:57+00:00" + }, + { + "name": "egulias/email-validator", + "version": "2.1.3", + "source": { + "type": "git", + "url": "https://github.com/egulias/EmailValidator.git", + "reference": "1bec00a10039b823cc94eef4eddd47dcd3b2ca04" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/1bec00a10039b823cc94eef4eddd47dcd3b2ca04", + "reference": "1bec00a10039b823cc94eef4eddd47dcd3b2ca04", + "shasum": "" + }, + "require": { + "doctrine/lexer": "^1.0.1", + "php": ">= 5.5" + }, + "require-dev": { + "dominicsayers/isemail": "dev-master", + "phpunit/phpunit": "^4.8.35", + "satooshi/php-coveralls": "^1.0.1" + }, + "suggest": { + "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Egulias\\EmailValidator\\": "EmailValidator" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Eduardo Gulias Davis" + } + ], + "description": "A library for validating emails against several RFCs", + "homepage": "https://github.com/egulias/EmailValidator", + "keywords": [ + "email", + "emailvalidation", + "emailvalidator", + "validation", + "validator" + ], + "time": "2017-11-15T23:40:40+00:00" + }, { "name": "erusev/parsedown", "version": "1.7.1", @@ -613,60 +724,6 @@ ], "time": "2015-06-14T21:17:01+00:00" }, - { - "name": "doctrine/lexer", - "version": "v1.0.1", - "source": { - "type": "git", - "url": "https://github.com/doctrine/lexer.git", - "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", - "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\Lexer\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "lexer", - "parser" - ], - "time": "2014-09-09T13:34:57+00:00" - }, { "name": "friendsofphp/php-cs-fixer", "version": "v2.10.4", From 599f3104f6fc70efd0e90dc3c872d1b373cba51e Mon Sep 17 00:00:00 2001 From: m Date: Tue, 3 Apr 2018 13:21:47 +0200 Subject: [PATCH 3/4] new test for InputService -> filterMail --- .../Services/InputServiceUnitTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 app/tests/Framadate/Services/InputServiceUnitTest.php diff --git a/app/tests/Framadate/Services/InputServiceUnitTest.php b/app/tests/Framadate/Services/InputServiceUnitTest.php new file mode 100644 index 0000000..cbbb36d --- /dev/null +++ b/app/tests/Framadate/Services/InputServiceUnitTest.php @@ -0,0 +1,41 @@ +filterMail($email); + + $this->assertSame($expected, $filtered); + + } + + + function liste_emails() + { + + return [ + // valids addresses + "valid address" => ["example@example.com", "example@example.com"], + "local address" => ["test@localhost", "test@localhost"], + "IP address" => ["ip.email@127.0.0.1", "ip.email@127.0.0.1"], + "with spaces arround" => [" with@spaces ", "with@spaces"], + "unicode caracters" => ["unicode.éà@idn-œ.com", "unicode.éà@idn-œ.com"], + // invalids addresses + "without domain" => ["without-domain", FALSE], + "space inside" => ["example @example.com", FALSE], + "forbidden chars" => ["special_chars.)#@example.com", FALSE], + ]; + + } + +} From 6f257f416a461215bbce5828f54e3412cb226d93 Mon Sep 17 00:00:00 2001 From: m Date: Tue, 3 Apr 2018 14:09:18 +0200 Subject: [PATCH 4/4] fix code style --- .../Framadate/Services/InputService.php | 1 - .../Services/InputServiceUnitTest.php | 20 ++++++------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/app/classes/Framadate/Services/InputService.php b/app/classes/Framadate/Services/InputService.php index 5f30885..904fe95 100644 --- a/app/classes/Framadate/Services/InputService.php +++ b/app/classes/Framadate/Services/InputService.php @@ -67,7 +67,6 @@ class InputService { } public function filterMail($mail) { - /////////////////////////////////////////////////////////////////////////////////////// // formatting diff --git a/app/tests/Framadate/Services/InputServiceUnitTest.php b/app/tests/Framadate/Services/InputServiceUnitTest.php index cbbb36d..8e0abc0 100644 --- a/app/tests/Framadate/Services/InputServiceUnitTest.php +++ b/app/tests/Framadate/Services/InputServiceUnitTest.php @@ -3,26 +3,20 @@ namespace Framadate\Services; use Framadate\FramaTestCase; -class InputServiceUnitTest extends FramaTestCase { - +class InputServiceUnitTest extends FramaTestCase +{ /** * @test * @dataProvider liste_emails */ - function test_filterMail($email, $expected) - { - + function test_filterMail($email, $expected) { $inputService = new InputService(); $filtered = $inputService->filterMail($email); $this->assertSame($expected, $filtered); - } - - function liste_emails() - { - + function liste_emails() { return [ // valids addresses "valid address" => ["example@example.com", "example@example.com"], @@ -32,10 +26,8 @@ class InputServiceUnitTest extends FramaTestCase { "unicode caracters" => ["unicode.éà@idn-œ.com", "unicode.éà@idn-œ.com"], // invalids addresses "without domain" => ["without-domain", FALSE], - "space inside" => ["example @example.com", FALSE], - "forbidden chars" => ["special_chars.)#@example.com", FALSE], + "space inside" => ["example example@example.com", FALSE], + "forbidden chars" => ["special_chars.@example.com", FALSE], ]; - } - }