Issue #2755401 by alexpott, naveenvalecha, bonus, Xano, cilefen, dawehner, mohit_aghera, markdorison, david_garcia: Upgrade EmailValidator to 2.x
							parent
							
								
									4052d65e7c
								
							
						
					
					
						commit
						9e7b020ff4
					
				| 
						 | 
				
			
			@ -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",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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\Plugin\ContainerFactoryPluginInterface;
 | 
			
		|||
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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue