Skip to content

Commit f77e643

Browse files
MAGETWO-64901: Bypassing outdated TLD validation
1 parent 78b7580 commit f77e643

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

lib/internal/Magento/Framework/Validator/EmailAddress.php

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,35 @@
77
*/
88
namespace Magento\Framework\Validator;
99

10-
use Zend_Config;
11-
1210
class EmailAddress extends \Zend_Validate_EmailAddress implements \Magento\Framework\Validator\ValidatorInterface
1311
{
1412
/**
15-
* Instantiates email validator for local use
13+
* Instantiates hostname validator for local use.
14+
* TLD validation is off by default.
1615
*
1716
* The following option keys are supported:
1817
* 'hostname' => A hostname validator, see Zend_Validate_Hostname
1918
* 'allow' => Options for the hostname validator, see Zend_Validate_Hostname::ALLOW_*
2019
* 'mx' => If MX check should be enabled, boolean
2120
* 'deep' => If a deep MX check should be done, boolean
22-
* 'tld' => If TLD validation should be done, boolean, default false
2321
*
24-
* @param array $options OPTIONAL
22+
* @param array|string|Zend_Config $options OPTIONAL
2523
*/
2624
public function __construct($options = [])
2725
{
28-
if ($options instanceof Zend_Config) {
29-
$options = $options->toArray();
30-
} elseif (!is_array($options)) {
31-
$options = func_get_args();
32-
$temp['allow'] = array_shift($options);
33-
if (!empty($options)) {
34-
$temp['mx'] = array_shift($options);
35-
}
36-
37-
if (!empty($options)) {
38-
$temp['hostname'] = array_shift($options);
39-
}
40-
41-
if (!empty($options)) {
42-
$temp['tld'] = array_shift($options);
43-
}
44-
45-
$options = $temp;
46-
}
4726
parent::__construct($options);
4827

49-
$this->getHostnameValidator()->setValidateTld(array_key_exists('tld', $options) ? $options['tld'] : false);
28+
$this->getHostnameValidator()->setValidateTld(false);
29+
}
30+
31+
/**
32+
* Sets whether or not top-level domains should be validated
33+
*
34+
* @param bool $shouldValidate
35+
* @return void
36+
*/
37+
public function setValidateTld(bool $shouldValidate)
38+
{
39+
$this->getHostnameValidator()->setValidateTld($shouldValidate);
5040
}
5141
}

lib/internal/Magento/Framework/Validator/Test/Unit/EmailAddressTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ public function testDefaultValidateIgnoresTLD()
2222
}
2323

2424
/**
25-
* Test that the TLD validation can be enabled on construction
25+
* Test that the TLD validation can be enabled
2626
*/
2727
public function testCanValidateTLD()
2828
{
2929
/** @var EmailAddress $emailAddress */
30-
$emailAddress = new EmailAddress(['tld'=>true]);
30+
$emailAddress = new EmailAddress();
31+
$emailAddress->setValidateTld(true);
3132
$this->assertFalse($emailAddress->isValid("user@domain.unknown"));
3233
}
3334
}

0 commit comments

Comments
 (0)