diff --git a/composer.lock b/composer.lock index 4fcfb06381e0583fdcb54d589325cee23027d1a1..41e5a866f1e2f0a3d60116880e5c4109334f36ac 100644 --- a/composer.lock +++ b/composer.lock @@ -702,24 +702,29 @@ }, { "name": "egulias/email-validator", - "version": "1.2.14", + "version": "2.1.6", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "5642614492f0ca2064c01d60cc33284cc2f731a9" + "reference": "0578b32b30b22de3e8664f797cf846fc9246f786" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/5642614492f0ca2064c01d60cc33284cc2f731a9", - "reference": "5642614492f0ca2064c01d60cc33284cc2f731a9", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/0578b32b30b22de3e8664f797cf846fc9246f786", + "reference": "0578b32b30b22de3e8664f797cf846fc9246f786", "shasum": "" }, "require": { "doctrine/lexer": "^1.0.1", - "php": ">= 5.3.3" + "php": ">= 5.5" }, "require-dev": { - "phpunit/phpunit": "^4.8.24" + "dominicsayers/isemail": "dev-master", + "phpunit/phpunit": "^4.8.35||^5.7||^6.0", + "satooshi/php-coveralls": "^1.0.1" + }, + "suggest": { + "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" }, "type": "library", "extra": { @@ -728,8 +733,8 @@ } }, "autoload": { - "psr-0": { - "Egulias\\": "src/" + "psr-4": { + "Egulias\\EmailValidator\\": "EmailValidator" } }, "notification-url": "https://packagist.org/downloads/", @@ -741,7 +746,7 @@ "name": "Eduardo Gulias Davis" } ], - "description": "A library for validating emails", + "description": "A library for validating emails against several RFCs", "homepage": "https://github.com/egulias/EmailValidator", "keywords": [ "email", @@ -750,7 +755,7 @@ "validation", "validator" ], - "time": "2017-02-03T22:48:59+00:00" + "time": "2018-09-25T20:47:26+00:00" }, { "name": "guzzlehttp/guzzle", diff --git a/core/composer.json b/core/composer.json index abc5c3f7135d383093ebb81611fe8347daa0152c..8dfd8a10f2fb833e75ce701c4d39234f55a0e7e0 100644 --- a/core/composer.json +++ b/core/composer.json @@ -39,7 +39,7 @@ "easyrdf/easyrdf": "^0.9", "zendframework/zend-feed": "^2.4", "stack/builder": "^1.0", - "egulias/email-validator": "^1.2", + "egulias/email-validator": "^2.0", "masterminds/html5": "^2.1", "symfony/psr-http-message-bridge": "^1.0", "zendframework/zend-diactoros": "^1.1", diff --git a/core/core.services.yml b/core/core.services.yml index 9c60943d2575c2cb053632e70dd3b551e50f0903..074474874f6fbddb29c5eb78045d91dcf31799ff 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1689,7 +1689,7 @@ services: tags: - { name: placeholder_strategy, priority: -1000 } email.validator: - class: Egulias\EmailValidator\EmailValidator + class: Drupal\Component\Utility\EmailValidator update.post_update_registry: class: Drupal\Core\Update\UpdateRegistry factory: ['@update.post_update_registry_factory', create] diff --git a/core/lib/Drupal/Component/Utility/EmailValidator.php b/core/lib/Drupal/Component/Utility/EmailValidator.php new file mode 100644 index 0000000000000000000000000000000000000000..9e6a0a06cc02845dfe7fcf6804c2be2f94613680 --- /dev/null +++ b/core/lib/Drupal/Component/Utility/EmailValidator.php @@ -0,0 +1,33 @@ +<?php + +namespace Drupal\Component\Utility; + +use Egulias\EmailValidator\EmailValidator as EmailValidatorUtility; +use Egulias\EmailValidator\Validation\EmailValidation; +use Egulias\EmailValidator\Validation\RFCValidation; + +/** + * Validates email addresses. + */ +class EmailValidator extends EmailValidatorUtility implements EmailValidatorInterface { + + /** + * Validates an email address. + * + * @param string $email + * A string containing an email address. + * @param \Egulias\EmailValidator\Validation\EmailValidation|null $email_validation + * This argument is ignored. If it is supplied an error will be triggered. + * See https://www.drupal.org/node/2997196. + * + * @return bool + * TRUE if the address is valid. + */ + public function isValid($email, EmailValidation $email_validation = NULL) { + if ($email_validation) { + throw new \BadMethodCallException('Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196'); + } + return parent::isValid($email, (new RFCValidation())); + } + +} diff --git a/core/lib/Drupal/Component/Utility/EmailValidatorInterface.php b/core/lib/Drupal/Component/Utility/EmailValidatorInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..930598efa05d1ac542640ef91ae911b1b2fb6896 --- /dev/null +++ b/core/lib/Drupal/Component/Utility/EmailValidatorInterface.php @@ -0,0 +1,21 @@ +<?php + +namespace Drupal\Component\Utility; + +/** + * Validates email addresses. + */ +interface EmailValidatorInterface { + + /** + * Validates an email address. + * + * @param string $email + * A string containing an email address. + * + * @return bool + * TRUE if the address is valid. + */ + public function isValid($email); + +} diff --git a/core/modules/action/src/Plugin/Action/EmailAction.php b/core/modules/action/src/Plugin/Action/EmailAction.php index 1780f3b689bf746e50b898a5cba151f2db8fb9e7..0791a3f99889a7ec438826f106933cbc7d3b41f8 100644 --- a/core/modules/action/src/Plugin/Action/EmailAction.php +++ b/core/modules/action/src/Plugin/Action/EmailAction.php @@ -3,6 +3,7 @@ namespace Drupal\action\Plugin\Action; use Drupal\Component\Render\PlainTextOutput; +use Drupal\Component\Utility\EmailValidatorInterface; use Drupal\Core\Access\AccessResult; use Drupal\Core\Action\ConfigurableActionBase; use Drupal\Core\Entity\EntityManagerInterface; @@ -13,7 +14,6 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\Utility\Token; use Psr\Log\LoggerInterface; -use Egulias\EmailValidator\EmailValidator; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -65,7 +65,7 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug /** * The email validator. * - * @var \Egulias\EmailValidator\EmailValidator + * @var \Drupal\Component\Utility\EmailValidatorInterface */ protected $emailValidator; @@ -88,10 +88,10 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug * The mail manager. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. - * @param \Egulias\EmailValidator\EmailValidator $email_validator + * @param \Drupal\Component\Utility\EmailValidatorInterface $email_validator * The email validator. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, EntityManagerInterface $entity_manager, LoggerInterface $logger, MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager, EmailValidator $email_validator) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, EntityManagerInterface $entity_manager, LoggerInterface $logger, MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager, EmailValidatorInterface $email_validator) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->token = $token; diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php index cdf7765a4a87a5a89de6993eae412b4d4ce0fcaf..5ca2fc49d1adb8643acd13713945bb1d36fa1286 100644 --- a/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -2,13 +2,13 @@ namespace Drupal\contact; +use Drupal\Component\Utility\EmailValidatorInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\ConfigFormBaseTrait; use Drupal\Core\Form\FormStateInterface; -use Egulias\EmailValidator\EmailValidator; use Drupal\Core\Path\PathValidatorInterface; use Drupal\Core\Render\Element\PathElement; @@ -23,7 +23,7 @@ class ContactFormEditForm extends EntityForm implements ContainerInjectionInterf /** * The email validator. * - * @var \Egulias\EmailValidator\EmailValidator + * @var \Drupal\Component\Utility\EmailValidatorInterface */ protected $emailValidator; @@ -37,12 +37,12 @@ class ContactFormEditForm extends EntityForm implements ContainerInjectionInterf /** * Constructs a new ContactFormEditForm. * - * @param \Egulias\EmailValidator\EmailValidator $email_validator + * @param \Drupal\Component\Utility\EmailValidatorInterface $email_validator * The email validator. * @param \Drupal\Core\Path\PathValidatorInterface $path_validator * The path validator service. */ - public function __construct(EmailValidator $email_validator, PathValidatorInterface $path_validator) { + public function __construct(EmailValidatorInterface $email_validator, PathValidatorInterface $path_validator) { $this->emailValidator = $email_validator; $this->pathValidator = $path_validator; } diff --git a/core/modules/update/src/UpdateSettingsForm.php b/core/modules/update/src/UpdateSettingsForm.php index 2a4e30d4896303559c2d85802a2a31ab8c2abebd..0717117d21bfcdec7801fe6d0f742eafe41297dc 100644 --- a/core/modules/update/src/UpdateSettingsForm.php +++ b/core/modules/update/src/UpdateSettingsForm.php @@ -2,11 +2,11 @@ namespace Drupal\update; +use Drupal\Component\Utility\EmailValidatorInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; -use Egulias\EmailValidator\EmailValidator; /** * Configure update settings for this site. @@ -18,17 +18,17 @@ class UpdateSettingsForm extends ConfigFormBase implements ContainerInjectionInt /** * The email validator. * - * @var \Egulias\EmailValidator\EmailValidator + * @var \Drupal\Component\Utility\EmailValidatorInterface */ protected $emailValidator; /** * Constructs a new UpdateSettingsForm. * - * @param \Egulias\EmailValidator\EmailValidator $email_validator + * @param \Drupal\Component\Utility\EmailValidatorInterface $email_validator * The email validator. */ - public function __construct(EmailValidator $email_validator) { + public function __construct(EmailValidatorInterface $email_validator) { $this->emailValidator = $email_validator; } diff --git a/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php b/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9185d01f32cb0234ebad65945a0ee095bfaa11ab --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php @@ -0,0 +1,45 @@ +<?php + +namespace Drupal\Tests\Component\Utility; + +use Drupal\Component\Utility\EmailValidator; +use Egulias\EmailValidator\Validation\RFCValidation; +use PHPUnit\Framework\TestCase; + +/** + * Tests the EmailValidator utility class. + * + * @coversDefaultClass \Drupal\Component\Utility\EmailValidator + * @group Utility + */ +class EmailValidatorTest extends TestCase { + + /** + * @covers ::isValid + */ + public function testIsValid() { + // Note that \Drupal\Component\Utility\EmailValidator wraps + // \Egulias\EmailValidator\EmailValidator so we don't do anything more than + // test that the wrapping works since the dependency has its own test + // coverage. + $validator = new EmailValidator(); + $this->assertTrue($validator->isValid('example@example.com')); + $this->assertFalse($validator->isValid('example@example.com@')); + } + + /** + * @covers ::isValid + */ + public function testIsValidException() { + $validator = new EmailValidator(); + if (method_exists($this, 'expectException')) { + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196'); + } + else { + $this->setExpectedException(\BadMethodCallException::class, 'Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196'); + } + $validator->isValid('example@example.com', (new RFCValidation())); + } + +}