From c7362242f18ed2dafc5f54ebe180ff2fcb10d1e0 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sat, 1 Apr 2017 16:24:53 +0200 Subject: [PATCH 01/13] Make email validation only validate @ sign presence, fixes #4547 --- .../Model/Metadata/Form/AbstractData.php | 20 +++++++++---------- .../Model/Metadata/Form/AbstractDataTest.php | 2 +- .../Eav/Model/Attribute/Data/AbstractData.php | 20 +++++++++---------- .../view/base/web/js/lib/validation/rules.js | 4 ++-- .../User/Model/UserValidationRules.php | 2 +- .../Framework/Validator/EmailAddress.php | 9 +++++++++ lib/web/jquery/jquery.validate.js | 3 ++- lib/web/mage/validation.js | 4 ++-- lib/web/prototype/validation.js | 3 ++- 9 files changed, 39 insertions(+), 28 deletions(-) diff --git a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php index 6dab7ca3bdbcf..eebed42a645b0 100644 --- a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php +++ b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php @@ -336,42 +336,42 @@ protected function _validateInputRule($value) __("'%value%' appears to be a DNS hostname but cannot extract TLD part") __("'%value%' appears to be a DNS hostname but cannot match TLD against known list") */ - $validator = new \Zend_Validate_EmailAddress(); + $validator = new \Magento\Framework\Validator\EmailAddress(); $validator->setMessage( __('"%1" invalid type entered.', $label), - \Zend_Validate_EmailAddress::INVALID + \Magento\Framework\Validator\EmailAddress::INVALID ); $validator->setMessage( __('"%1" is not a valid email address.', $label), - \Zend_Validate_EmailAddress::INVALID_FORMAT + \Magento\Framework\Validator\EmailAddress::INVALID_FORMAT ); $validator->setMessage( __('"%1" is not a valid hostname.', $label), - \Zend_Validate_EmailAddress::INVALID_HOSTNAME + \Magento\Framework\Validator\EmailAddress::INVALID_HOSTNAME ); $validator->setMessage( __('"%1" is not a valid hostname.', $label), - \Zend_Validate_EmailAddress::INVALID_MX_RECORD + \Magento\Framework\Validator\EmailAddress::INVALID_MX_RECORD ); $validator->setMessage( __('"%1" is not a valid hostname.', $label), - \Zend_Validate_EmailAddress::INVALID_MX_RECORD + \Magento\Framework\Validator\EmailAddress::INVALID_MX_RECORD ); $validator->setMessage( __('"%1" is not a valid email address.', $label), - \Zend_Validate_EmailAddress::DOT_ATOM + \Magento\Framework\Validator\EmailAddress::DOT_ATOM ); $validator->setMessage( __('"%1" is not a valid email address.', $label), - \Zend_Validate_EmailAddress::QUOTED_STRING + \Magento\Framework\Validator\EmailAddress::QUOTED_STRING ); $validator->setMessage( __('"%1" is not a valid email address.', $label), - \Zend_Validate_EmailAddress::INVALID_LOCAL_PART + \Magento\Framework\Validator\EmailAddress::INVALID_LOCAL_PART ); $validator->setMessage( __('"%1" uses too many characters.', $label), - \Zend_Validate_EmailAddress::LENGTH_EXCEEDED + \Magento\Framework\Validator\EmailAddress::LENGTH_EXCEEDED ); $validator->setMessage( __("'%value%' looks like an IP address, which is not an acceptable format."), diff --git a/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php b/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php index 8c142f2eddcb1..0eb88ce5d9c20 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php @@ -262,7 +262,7 @@ public function validateInputRuleDataProvider() 'email', [ // @codingStandardsIgnoreStart - \Zend_Validate_EmailAddress::INVALID_HOSTNAME => '"mylabel" is not a valid hostname.', + \Magento\Framework\Validator\EmailAddress::INVALID_HOSTNAME => '"mylabel" is not a valid hostname.', \Zend_Validate_Hostname::INVALID_HOSTNAME => "'#\$' does not match the expected structure for a DNS hostname", \Zend_Validate_Hostname::INVALID_LOCAL_NAME => "'#\$' does not look like a valid local network name." // @codingStandardsIgnoreEnd diff --git a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php index aa569b35db9aa..1382f08b28abe 100644 --- a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php +++ b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php @@ -364,42 +364,42 @@ protected function _validateInputRule($value) __("'%value%' appears to be a DNS hostname but cannot extract TLD part") __("'%value%' appears to be a DNS hostname but cannot match TLD against known list") */ - $validator = new \Zend_Validate_EmailAddress(); + $validator = new \Magento\Framework\Validator\EmailAddress(); $validator->setMessage( __('"%1" invalid type entered.', $label), - \Zend_Validate_EmailAddress::INVALID + \Magento\Framework\Validator\EmailAddress::INVALID ); $validator->setMessage( __('"%1" is not a valid email address.', $label), - \Zend_Validate_EmailAddress::INVALID_FORMAT + \Magento\Framework\Validator\EmailAddress::INVALID_FORMAT ); $validator->setMessage( __('"%1" is not a valid hostname.', $label), - \Zend_Validate_EmailAddress::INVALID_HOSTNAME + \Magento\Framework\Validator\EmailAddress::INVALID_HOSTNAME ); $validator->setMessage( __('"%1" is not a valid hostname.', $label), - \Zend_Validate_EmailAddress::INVALID_MX_RECORD + \Magento\Framework\Validator\EmailAddress::INVALID_MX_RECORD ); $validator->setMessage( __('"%1" is not a valid hostname.', $label), - \Zend_Validate_EmailAddress::INVALID_MX_RECORD + \Magento\Framework\Validator\EmailAddress::INVALID_MX_RECORD ); $validator->setMessage( __('"%1" is not a valid email address.', $label), - \Zend_Validate_EmailAddress::DOT_ATOM + \Magento\Framework\Validator\EmailAddress::DOT_ATOM ); $validator->setMessage( __('"%1" is not a valid email address.', $label), - \Zend_Validate_EmailAddress::QUOTED_STRING + \Magento\Framework\Validator\EmailAddress::QUOTED_STRING ); $validator->setMessage( __('"%1" is not a valid email address.', $label), - \Zend_Validate_EmailAddress::INVALID_LOCAL_PART + \Magento\Framework\Validator\EmailAddress::INVALID_LOCAL_PART ); $validator->setMessage( __('"%1" uses too many characters.', $label), - \Zend_Validate_EmailAddress::LENGTH_EXCEEDED + \Magento\Framework\Validator\EmailAddress::LENGTH_EXCEEDED ); $validator->setMessage( __("'%value%' looks like an IP address, which is not an acceptable format."), diff --git a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js index 9792edf0266cf..b00b9c627cd0f 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js @@ -419,13 +419,13 @@ define([ ], 'validate-email': [ function (value) { - return utils.isEmptyNoTrim(value) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(value);//eslint-disable-line max-len + return utils.isEmptyNoTrim(value) || value.indexOf('@') !== -1; }, $.mage.__('Please enter a valid email address (Ex: johndoe@domain.com).') ], 'validate-emailSender': [ function (value) { - return utils.isEmptyNoTrim(value) || /^[\S ]+$/.test(value); + return utils.isEmptyNoTrim(value) || value.indexOf('@') !== -1; }, $.mage.__('Please enter a valid email address (Ex: johndoe@domain.com).') ], diff --git a/app/code/Magento/User/Model/UserValidationRules.php b/app/code/Magento/User/Model/UserValidationRules.php index 7dfd2a17d1ae8..2cc82304878fa 100644 --- a/app/code/Magento/User/Model/UserValidationRules.php +++ b/app/code/Magento/User/Model/UserValidationRules.php @@ -35,7 +35,7 @@ public function addUserInfoRules(\Magento\Framework\Validator\DataObject $valida $lastNameNotEmpty = new NotEmpty(); $lastNameNotEmpty->setMessage(__('Last Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY); $emailValidity = new EmailAddress(); - $emailValidity->setMessage(__('Please enter a valid email.'), \Zend_Validate_EmailAddress::INVALID); + $emailValidity->setMessage(__('Please enter a valid email.'), \Magento\Framework\Validator\EmailAddress::INVALID); /** @var $validator \Magento\Framework\Validator\DataObject */ $validator->addRule( diff --git a/lib/internal/Magento/Framework/Validator/EmailAddress.php b/lib/internal/Magento/Framework/Validator/EmailAddress.php index 4ad63851412f9..7dc13ab63150f 100644 --- a/lib/internal/Magento/Framework/Validator/EmailAddress.php +++ b/lib/internal/Magento/Framework/Validator/EmailAddress.php @@ -9,4 +9,13 @@ class EmailAddress extends \Zend_Validate_EmailAddress implements \Magento\Framework\Validator\ValidatorInterface { + public function isValid($value) + { + if (false === \strpos($value, '@')) { + $this->_error(self::INVALID); + return false; + } + + return true; + } } diff --git a/lib/web/jquery/jquery.validate.js b/lib/web/jquery/jquery.validate.js index a7f85a23137a4..2a8d8eca81720 100644 --- a/lib/web/jquery/jquery.validate.js +++ b/lib/web/jquery/jquery.validate.js @@ -1113,7 +1113,8 @@ // http://docs.jquery.com/Plugins/Validation/Methods/email email: function (value, element) { // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ - return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value); + // return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value); + return this.optional(element) || value.indexOf('@') !== -1; }, // http://docs.jquery.com/Plugins/Validation/Methods/url diff --git a/lib/web/mage/validation.js b/lib/web/mage/validation.js index 5f8ce5ea69546..033d35689cdf2 100644 --- a/lib/web/mage/validation.js +++ b/lib/web/mage/validation.js @@ -586,13 +586,13 @@ ], 'validate-email': [ function (v) { - return $.mage.isEmptyNoTrim(v) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(v); //eslint-disable-line max-len + return $.mage.isEmptyNoTrim(v) || v.indexOf('@') !== -1; }, $.mage.__('Please enter a valid email address (Ex: johndoe@domain.com).') ], 'validate-emailSender': [ function (v) { - return $.mage.isEmptyNoTrim(v) || /^[\S ]+$/.test(v); + return $.mage.isEmptyNoTrim(v) || v.indexOf('@') !== -1; }, $.mage.__('Please enter a valid email address (Ex: johndoe@domain.com).') ], diff --git a/lib/web/prototype/validation.js b/lib/web/prototype/validation.js index 616d49496e2a7..82c7bd362669e 100644 --- a/lib/web/prototype/validation.js +++ b/lib/web/prototype/validation.js @@ -560,7 +560,8 @@ Validation.addAllThese([ ['validate-email', 'Please enter a valid email address (Ex: johndoe@domain.com).', function (v) { //return Validation.get('IsEmpty').test(v) || /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v) //return Validation.get('IsEmpty').test(v) || /^[\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9][\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9\.]{1,30}[\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9]@([a-z0-9_-]{1,30}\.){1,5}[a-z]{2,4}$/i.test(v) - return Validation.get('IsEmpty').test(v) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(v) + //return Validation.get('IsEmpty').test(v) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(v) + return Validation.get('IsEmpty').test(v) || v.indexOf('@') !== -1 }], ['validate-emailSender', 'Please use only visible characters and spaces.', function (v) { return Validation.get('IsEmpty').test(v) || /^[\S ]+$/.test(v) From dc8867d40ca763a0a11012b1700659251b5ed378 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 21:05:57 +0200 Subject: [PATCH 02/13] Remove dependency on Zend validator, make validator logic more similar to other Magento validators, fix code errors --- .../Model/Metadata/Form/AbstractData.php | 89 +----------------- .../Model/Metadata/Form/AbstractDataTest.php | 1 - .../Eav/Model/Attribute/Data/AbstractData.php | 91 +------------------ .../User/Model/UserValidationRules.php | 2 +- .../Magento/Framework/Validator/Email.php | 44 +++++++++ .../Framework/Validator/EmailAddress.php | 13 +-- lib/web/mage/validation.js | 2 +- 7 files changed, 59 insertions(+), 183 deletions(-) create mode 100644 lib/internal/Magento/Framework/Validator/Email.php diff --git a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php index eebed42a645b0..acaf35c4bdad8 100644 --- a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php +++ b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php @@ -11,6 +11,7 @@ namespace Magento\Customer\Model\Metadata\Form; use Magento\Framework\Api\ArrayObjectSearch; +use Magento\Framework\App\ObjectManager; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -324,93 +325,11 @@ protected function _validateInputRule($value) break; case 'email': /** - __("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded") - __("Invalid type given. String expected") - __("'%value%' appears to be a DNS hostname but contains a dash in an invalid position") - __("'%value%' does not match the expected structure for a DNS hostname") - __("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'") - __("'%value%' does not appear to be a valid local network name") - __("'%value%' does not appear to be a valid URI hostname") - __("'%value%' appears to be an IP address, but IP addresses are not allowed") - __("'%value%' appears to be a local network name but local network names are not allowed") - __("'%value%' appears to be a DNS hostname but cannot extract TLD part") - __("'%value%' appears to be a DNS hostname but cannot match TLD against known list") + __('"%1" is not a valid email address.') */ - $validator = new \Magento\Framework\Validator\EmailAddress(); - $validator->setMessage( - __('"%1" invalid type entered.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID - ); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_FORMAT - ); - $validator->setMessage( - __('"%1" is not a valid hostname.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_HOSTNAME - ); - $validator->setMessage( - __('"%1" is not a valid hostname.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_MX_RECORD - ); - $validator->setMessage( - __('"%1" is not a valid hostname.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_MX_RECORD - ); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\EmailAddress::DOT_ATOM - ); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\EmailAddress::QUOTED_STRING - ); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_LOCAL_PART - ); - $validator->setMessage( - __('"%1" uses too many characters.', $label), - \Magento\Framework\Validator\EmailAddress::LENGTH_EXCEEDED - ); - $validator->setMessage( - __("'%value%' looks like an IP address, which is not an acceptable format."), - \Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED - ); - $validator->setMessage( - __("'%value%' looks like a DNS hostname but we cannot match the TLD against known list."), - \Zend_Validate_Hostname::UNKNOWN_TLD - ); - $validator->setMessage( - __("'%value%' looks like a DNS hostname but contains a dash in an invalid position."), - \Zend_Validate_Hostname::INVALID_DASH - ); - $validator->setMessage( - __( - "'%value%' looks like a DNS hostname but we cannot match it against the hostname schema for TLD '%tld%'." - ), - \Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA - ); - $validator->setMessage( - __("'%value%' looks like a DNS hostname but cannot extract TLD part."), - \Zend_Validate_Hostname::UNDECIPHERABLE_TLD - ); - $validator->setMessage( - __("'%value%' does not look like a valid local network name."), - \Zend_Validate_Hostname::INVALID_LOCAL_NAME - ); - $validator->setMessage( - __("'%value%' looks like a local network name, which is not an acceptable format."), - \Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED - ); - $validator->setMessage( - __( - "'%value%' appears to be a DNS hostname, but the given punycode notation cannot be decoded." - ), - \Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE - ); + $validator = ObjectManager::getInstance()->get(\Magento\Framework\Validator\Email::class); if (!$validator->isValid($value)) { - return array_unique($validator->getMessages()); + return [__('"%1" is not a valid email address.', $label)]; } break; case 'url': diff --git a/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php b/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php index 0eb88ce5d9c20..46e53c5cf6421 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php @@ -262,7 +262,6 @@ public function validateInputRuleDataProvider() 'email', [ // @codingStandardsIgnoreStart - \Magento\Framework\Validator\EmailAddress::INVALID_HOSTNAME => '"mylabel" is not a valid hostname.', \Zend_Validate_Hostname::INVALID_HOSTNAME => "'#\$' does not match the expected structure for a DNS hostname", \Zend_Validate_Hostname::INVALID_LOCAL_NAME => "'#\$' does not look like a valid local network name." // @codingStandardsIgnoreEnd diff --git a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php index 1382f08b28abe..8711b18b78620 100644 --- a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php +++ b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php @@ -10,6 +10,7 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\Exception\LocalizedException as CoreException; +use Magento\Framework\App\ObjectManager; /** * EAV Attribute Abstract Data Model @@ -352,93 +353,11 @@ protected function _validateInputRule($value) break; case 'email': /** - __("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded") - __("Invalid type given. String expected") - __("'%value%' appears to be a DNS hostname but contains a dash in an invalid position") - __("'%value%' does not match the expected structure for a DNS hostname") - __("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'") - __("'%value%' does not appear to be a valid local network name") - __("'%value%' does not appear to be a valid URI hostname") - __("'%value%' appears to be an IP address but IP addresses are not allowed") - __("'%value%' appears to be a local network name but local network names are not allowed") - __("'%value%' appears to be a DNS hostname but cannot extract TLD part") - __("'%value%' appears to be a DNS hostname but cannot match TLD against known list") - */ - $validator = new \Magento\Framework\Validator\EmailAddress(); - $validator->setMessage( - __('"%1" invalid type entered.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID - ); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_FORMAT - ); - $validator->setMessage( - __('"%1" is not a valid hostname.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_HOSTNAME - ); - $validator->setMessage( - __('"%1" is not a valid hostname.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_MX_RECORD - ); - $validator->setMessage( - __('"%1" is not a valid hostname.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_MX_RECORD - ); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\EmailAddress::DOT_ATOM - ); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\EmailAddress::QUOTED_STRING - ); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\EmailAddress::INVALID_LOCAL_PART - ); - $validator->setMessage( - __('"%1" uses too many characters.', $label), - \Magento\Framework\Validator\EmailAddress::LENGTH_EXCEEDED - ); - $validator->setMessage( - __("'%value%' looks like an IP address, which is not an acceptable format."), - \Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED - ); - $validator->setMessage( - __("'%value%' looks like a DNS hostname but we cannot match the TLD against known list."), - \Zend_Validate_Hostname::UNKNOWN_TLD - ); - $validator->setMessage( - __("'%value%' looks like a DNS hostname but contains a dash in an invalid position."), - \Zend_Validate_Hostname::INVALID_DASH - ); - $validator->setMessage( - __( - "'%value%' looks like a DNS hostname but we cannot match it against the hostname schema for TLD '%tld%'." - ), - \Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA - ); - $validator->setMessage( - __("'%value%' looks like a DNS hostname but cannot extract TLD part."), - \Zend_Validate_Hostname::UNDECIPHERABLE_TLD - ); - $validator->setMessage( - __("'%value%' does not look like a valid local network name."), - \Zend_Validate_Hostname::INVALID_LOCAL_NAME - ); - $validator->setMessage( - __("'%value%' looks like a local network name, which is not an acceptable format."), - \Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED - ); - $validator->setMessage( - __( - "'%value%' appears to be a DNS hostname, but the given punycode notation cannot be decoded." - ), - \Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE - ); + __('"%1" is not a valid email address.') + */ + $validator = ObjectManager::getInstance()->get(\Magento\Framework\Validator\Email::class); if (!$validator->isValid($value)) { - return array_unique($validator->getMessages()); + return [__('"%1" is not a valid email address.', $label)]; } break; case 'url': diff --git a/app/code/Magento/User/Model/UserValidationRules.php b/app/code/Magento/User/Model/UserValidationRules.php index 2cc82304878fa..8e2a273e1c09c 100644 --- a/app/code/Magento/User/Model/UserValidationRules.php +++ b/app/code/Magento/User/Model/UserValidationRules.php @@ -35,7 +35,7 @@ public function addUserInfoRules(\Magento\Framework\Validator\DataObject $valida $lastNameNotEmpty = new NotEmpty(); $lastNameNotEmpty->setMessage(__('Last Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY); $emailValidity = new EmailAddress(); - $emailValidity->setMessage(__('Please enter a valid email.'), \Magento\Framework\Validator\EmailAddress::INVALID); + $emailValidity->setMessage(__('Please enter a valid email.'), \Magento\Framework\Validator\Email::INVALID); /** @var $validator \Magento\Framework\Validator\DataObject */ $validator->addRule( diff --git a/lib/internal/Magento/Framework/Validator/Email.php b/lib/internal/Magento/Framework/Validator/Email.php new file mode 100644 index 0000000000000..79912937f6ed3 --- /dev/null +++ b/lib/internal/Magento/Framework/Validator/Email.php @@ -0,0 +1,44 @@ +lists = $lists; + } + + /** + * Validate email address contains '@' sign + * + * @param mixed $value + * @return bool + */ + public function isValid($value) + { + $isValid = true; + if (strrpos($value, '@') === false) { + $isValid = false; + } + + return $isValid; + } +} diff --git a/lib/internal/Magento/Framework/Validator/EmailAddress.php b/lib/internal/Magento/Framework/Validator/EmailAddress.php index 7dc13ab63150f..7af04643b19b3 100644 --- a/lib/internal/Magento/Framework/Validator/EmailAddress.php +++ b/lib/internal/Magento/Framework/Validator/EmailAddress.php @@ -5,17 +5,12 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +/** + * @deprecated + * @see \Magento\Framework\Validator\Email + */ namespace Magento\Framework\Validator; class EmailAddress extends \Zend_Validate_EmailAddress implements \Magento\Framework\Validator\ValidatorInterface { - public function isValid($value) - { - if (false === \strpos($value, '@')) { - $this->_error(self::INVALID); - return false; - } - - return true; - } } diff --git a/lib/web/mage/validation.js b/lib/web/mage/validation.js index 033d35689cdf2..f7fa299990cf6 100644 --- a/lib/web/mage/validation.js +++ b/lib/web/mage/validation.js @@ -592,7 +592,7 @@ ], 'validate-emailSender': [ function (v) { - return $.mage.isEmptyNoTrim(v) || v.indexOf('@') !== -1; + return $.mage.isEmptyNoTrim(v) || /^[\S ]+$/.test(v); }, $.mage.__('Please enter a valid email address (Ex: johndoe@domain.com).') ], From 4a3612f7efe11379a0c01385e26430f2ed2d0807 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 21:24:19 +0200 Subject: [PATCH 03/13] Add obsolete EmailAddress validator class --- .../testsuite/Magento/Test/Legacy/_files/obsolete_classes.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 6e2cdf1ab5309..a880a422d57aa 100755 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -3628,6 +3628,7 @@ ['Magento\ToolkitFramework\Helper\Cli'], ['Magento\ToolkitFramework\Config'], ['Magento\Framework\Locale\Validator', 'Magento\Framework\Validator\Locale'], + ['Magento\Framework\Validator\EmailAddress', 'Magento\Framework\Validator\Email'], ['Magento\ToolkitFramework\Fixture', 'Magento\Setup\Fixtures\Fixture'], ['Magento\ToolkitFramework\Application', 'Magento\Setup\Fixtures\FixtureModel'], ['Magento\Framework\Locale\Lists', 'Magento\Framework\Locale\TranslatedLists'], From 196994ded766bef32532617b57619a494677b644 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 21:59:09 +0200 Subject: [PATCH 04/13] Attempt to create Email validator by implementing AbstractValidator inteface --- .../Model/Metadata/Form/AbstractData.php | 9 +- .../Eav/Model/Attribute/Data/AbstractData.php | 9 +- .../User/Model/UserValidationRules.php | 4 +- .../Magento/Framework/Validator/Email.php | 85 +++++++++++++++---- 4 files changed, 84 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php index acaf35c4bdad8..7697ad42e4b6e 100644 --- a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php +++ b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php @@ -11,7 +11,6 @@ namespace Magento\Customer\Model\Metadata\Form; use Magento\Framework\Api\ArrayObjectSearch; -use Magento\Framework\App\ObjectManager; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -327,9 +326,13 @@ protected function _validateInputRule($value) /** __('"%1" is not a valid email address.') */ - $validator = ObjectManager::getInstance()->get(\Magento\Framework\Validator\Email::class); + $validator = new \Magento\Framework\Validator\Email(); + $validator->setMessage( + __('"%1" is not a valid email address.', $label), + \Magento\Framework\Validator\Email::INVALID + ); if (!$validator->isValid($value)) { - return [__('"%1" is not a valid email address.', $label)]; + return array_unique($validator->getMessages()); } break; case 'url': diff --git a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php index 8711b18b78620..6c244ed74ea17 100644 --- a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php +++ b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php @@ -10,7 +10,6 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\Exception\LocalizedException as CoreException; -use Magento\Framework\App\ObjectManager; /** * EAV Attribute Abstract Data Model @@ -355,9 +354,13 @@ protected function _validateInputRule($value) /** __('"%1" is not a valid email address.') */ - $validator = ObjectManager::getInstance()->get(\Magento\Framework\Validator\Email::class); + $validator = new \Magento\Framework\Validator\Email(); + $validator->setMessage( + __('"%1" is not a valid email address.', $label), + \Magento\Framework\Validator\Email::INVALID + ); if (!$validator->isValid($value)) { - return [__('"%1" is not a valid email address.', $label)]; + return array_unique($validator->getMessages()); } break; case 'url': diff --git a/app/code/Magento/User/Model/UserValidationRules.php b/app/code/Magento/User/Model/UserValidationRules.php index 8e2a273e1c09c..3d28220766af7 100644 --- a/app/code/Magento/User/Model/UserValidationRules.php +++ b/app/code/Magento/User/Model/UserValidationRules.php @@ -5,7 +5,7 @@ */ namespace Magento\User\Model; -use Magento\Framework\Validator\EmailAddress; +use Magento\Framework\Validator\Email; use Magento\Framework\Validator\NotEmpty; use Magento\Framework\Validator\Regex; use Magento\Framework\Validator\StringLength; @@ -34,7 +34,7 @@ public function addUserInfoRules(\Magento\Framework\Validator\DataObject $valida $firstNameNotEmpty->setMessage(__('First Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY); $lastNameNotEmpty = new NotEmpty(); $lastNameNotEmpty->setMessage(__('Last Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY); - $emailValidity = new EmailAddress(); + $emailValidity = new Email(); $emailValidity->setMessage(__('Please enter a valid email.'), \Magento\Framework\Validator\Email::INVALID); /** @var $validator \Magento\Framework\Validator\DataObject */ diff --git a/lib/internal/Magento/Framework/Validator/Email.php b/lib/internal/Magento/Framework/Validator/Email.php index 79912937f6ed3..e638294b91dd9 100644 --- a/lib/internal/Magento/Framework/Validator/Email.php +++ b/lib/internal/Magento/Framework/Validator/Email.php @@ -7,24 +7,16 @@ */ namespace Magento\Framework\Validator; -use Magento\Framework\Setup\Lists; - -class Email +class Email extends AbstractValidator implements \Magento\Framework\Validator\ValidatorInterface { - /** - * @var Lists - */ - protected $lists; + const INVALID = 'emailAddressInvalid'; /** - * Constructor + * Validation failure message template definitions * - * @param Lists $lists + * @var array */ - public function __construct(Lists $lists) - { - $this->lists = $lists; - } + protected $_messageTemplates = array(); /** * Validate email address contains '@' sign @@ -35,10 +27,73 @@ public function __construct(Lists $lists) public function isValid($value) { $isValid = true; - if (strrpos($value, '@') === false) { + if (!is_string($value) || strrpos($value, '@') === false) { $isValid = false; + $this->_error(self::INVALID, $value); } - + return $isValid; } + + /** + * Sets the validation failure message template for a particular key + * + * @param string $messageString + * @param string $messageKey OPTIONAL + * @return AbstractValidator Provides a fluent interface + * @throws Exception + */ + public function setMessage($messageString, $messageKey = null) + { + if ($messageKey === null) { + $keys = array_keys($this->_messageTemplates); + foreach($keys as $key) { + $this->setMessage($messageString, $key); + } + return $this; + } + + if (!isset($this->_messageTemplates[$messageKey])) { + throw new Exception("No message template exists for key '$messageKey'"); + } + + $this->_messageTemplates[$messageKey] = $messageString; + return $this; + } + + /** + * @param string $messageKey + * @param string $value OPTIONAL + * @return void + */ + protected function _error($messageKey, $value = null) + { + if ($messageKey === null) { + $keys = array_keys($this->_messageTemplates); + $messageKey = current($keys); + } + + $this->_messages[$messageKey] = $this->_createMessage($messageKey, $value); + } + + /** + * Constructs and returns a validation failure message with the given message key and value. + * + * Returns null if and only if $messageKey does not correspond to an existing template. + * + * If a translator is available and a translation exists for $messageKey, + * the translation will be used. + * + * @param string $messageKey + * @param string $value + * @return string + */ + protected function _createMessage($messageKey, $value) + { + if(!isset($this->_messageTemplates[$messageKey])){ + return null; + } + + return $this->_messageTemplates[$messageKey]; + } } From c6fbf5c717b7374ae0fe6982d9a944a7d5f3b765 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 22:10:57 +0200 Subject: [PATCH 05/13] Fix exception, use Phrase instead of plain string --- lib/internal/Magento/Framework/Validator/Email.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Validator/Email.php b/lib/internal/Magento/Framework/Validator/Email.php index e638294b91dd9..329cbede0f31a 100644 --- a/lib/internal/Magento/Framework/Validator/Email.php +++ b/lib/internal/Magento/Framework/Validator/Email.php @@ -54,7 +54,8 @@ public function setMessage($messageString, $messageKey = null) } if (!isset($this->_messageTemplates[$messageKey])) { - throw new Exception("No message template exists for key '$messageKey'"); + $exceptionPhrase = new \Magento\Framework\Phrase("No message template exists for key '$messageKey'"); + throw new Exception($exceptionPhrase); } $this->_messageTemplates[$messageKey] = $messageString; @@ -75,7 +76,7 @@ protected function _error($messageKey, $value = null) $this->_messages[$messageKey] = $this->_createMessage($messageKey, $value); } - + /** * Constructs and returns a validation failure message with the given message key and value. * From 5d7d971285c69ea6eff43c76acd9beed89cea412 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 22:17:58 +0200 Subject: [PATCH 06/13] Fix logical error --- lib/internal/Magento/Framework/Validator/Email.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/internal/Magento/Framework/Validator/Email.php b/lib/internal/Magento/Framework/Validator/Email.php index 329cbede0f31a..a4c2e3d746350 100644 --- a/lib/internal/Magento/Framework/Validator/Email.php +++ b/lib/internal/Magento/Framework/Validator/Email.php @@ -41,7 +41,6 @@ public function isValid($value) * @param string $messageString * @param string $messageKey OPTIONAL * @return AbstractValidator Provides a fluent interface - * @throws Exception */ public function setMessage($messageString, $messageKey = null) { @@ -53,11 +52,6 @@ public function setMessage($messageString, $messageKey = null) return $this; } - if (!isset($this->_messageTemplates[$messageKey])) { - $exceptionPhrase = new \Magento\Framework\Phrase("No message template exists for key '$messageKey'"); - throw new Exception($exceptionPhrase); - } - $this->_messageTemplates[$messageKey] = $messageString; return $this; } @@ -88,11 +82,13 @@ protected function _error($messageKey, $value = null) * @param string $messageKey * @param string $value * @return string + * @throws Exception */ protected function _createMessage($messageKey, $value) { - if(!isset($this->_messageTemplates[$messageKey])){ - return null; + if (!isset($this->_messageTemplates[$messageKey])) { + $exceptionPhrase = new \Magento\Framework\Phrase("No message template exists for key '$messageKey'"); + throw new Exception($exceptionPhrase); } return $this->_messageTemplates[$messageKey]; From 2775007ccbb5d89b6e8453d6c7e805b1c07641d5 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 22:20:36 +0200 Subject: [PATCH 07/13] Fix logical error --- .../Magento/Framework/Validator/Email.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/Validator/Email.php b/lib/internal/Magento/Framework/Validator/Email.php index a4c2e3d746350..62e334d0d9102 100644 --- a/lib/internal/Magento/Framework/Validator/Email.php +++ b/lib/internal/Magento/Framework/Validator/Email.php @@ -16,7 +16,9 @@ class Email extends AbstractValidator implements \Magento\Framework\Validator\Va * * @var array */ - protected $_messageTemplates = array(); + protected $_messageTemplates = array( + self::INVALID => "Email address is not valid." + ); /** * Validate email address contains '@' sign @@ -41,6 +43,7 @@ public function isValid($value) * @param string $messageString * @param string $messageKey OPTIONAL * @return AbstractValidator Provides a fluent interface + * @throws Exception */ public function setMessage($messageString, $messageKey = null) { @@ -52,6 +55,11 @@ public function setMessage($messageString, $messageKey = null) return $this; } + if (!isset($this->_messageTemplates[$messageKey])) { + $exceptionPhrase = new \Magento\Framework\Phrase("No message template exists for key '$messageKey'"); + throw new Exception($exceptionPhrase); + } + $this->_messageTemplates[$messageKey] = $messageString; return $this; } @@ -82,13 +90,11 @@ protected function _error($messageKey, $value = null) * @param string $messageKey * @param string $value * @return string - * @throws Exception */ protected function _createMessage($messageKey, $value) { - if (!isset($this->_messageTemplates[$messageKey])) { - $exceptionPhrase = new \Magento\Framework\Phrase("No message template exists for key '$messageKey'"); - throw new Exception($exceptionPhrase); + if(!isset($this->_messageTemplates[$messageKey])){ + return null; } return $this->_messageTemplates[$messageKey]; From a476b053d0cb47821b8c473fadad996a5bef5503 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 22:28:03 +0200 Subject: [PATCH 08/13] Unify messages --- lib/internal/Magento/Framework/Validator/Email.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Validator/Email.php b/lib/internal/Magento/Framework/Validator/Email.php index 62e334d0d9102..d879573d6a74d 100644 --- a/lib/internal/Magento/Framework/Validator/Email.php +++ b/lib/internal/Magento/Framework/Validator/Email.php @@ -17,7 +17,7 @@ class Email extends AbstractValidator implements \Magento\Framework\Validator\Va * @var array */ protected $_messageTemplates = array( - self::INVALID => "Email address is not valid." + self::INVALID => '"%1" is not a valid email address.' ); /** @@ -96,7 +96,9 @@ protected function _createMessage($messageKey, $value) if(!isset($this->_messageTemplates[$messageKey])){ return null; } + $message = $this->_messageTemplates[$messageKey]; + $message = str_replace('%1', $value, $message); - return $this->_messageTemplates[$messageKey]; + return $message; } } From c8239e0e2f6dfe628225966673839e84cb041d59 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 23:03:23 +0200 Subject: [PATCH 09/13] Fix integration test failure, we no longer check for valid hostname in email address --- .../testsuite/Magento/User/Controller/Adminhtml/UserTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserTest.php b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserTest.php index b7562b9727a67..06320f8a12210 100644 --- a/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserTest.php +++ b/dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/UserTest.php @@ -232,7 +232,7 @@ public function testValidateActionError() 'username' => 'admin2', 'firstname' => 'new firstname', 'lastname' => 'new lastname', - 'email' => 'example@domain.cim', + 'email' => 'example.domain.com', 'password' => 'password123', 'password_confirmation' => 'password123', ]; @@ -245,6 +245,6 @@ public function testValidateActionError() $body = $this->getResponse()->getBody(); $this->assertContains('{"error":1,"html_message":', $body); - $this->assertContains("'domain.cim' is not a valid hostname for email address 'example@domain.cim'", $body); + $this->assertContains('"example.domain.com" is not a valid email address.', $body); } } From 9263b0e55eafbd41790c088d98c4d962316cc410 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 23:06:07 +0200 Subject: [PATCH 10/13] Fix failing static tests --- lib/internal/Magento/Framework/Validator/Email.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Validator/Email.php b/lib/internal/Magento/Framework/Validator/Email.php index d879573d6a74d..0868a9b3ede0b 100644 --- a/lib/internal/Magento/Framework/Validator/Email.php +++ b/lib/internal/Magento/Framework/Validator/Email.php @@ -16,9 +16,9 @@ class Email extends AbstractValidator implements \Magento\Framework\Validator\Va * * @var array */ - protected $_messageTemplates = array( + protected $_messageTemplates = [ self::INVALID => '"%1" is not a valid email address.' - ); + ]; /** * Validate email address contains '@' sign @@ -49,7 +49,7 @@ public function setMessage($messageString, $messageKey = null) { if ($messageKey === null) { $keys = array_keys($this->_messageTemplates); - foreach($keys as $key) { + foreach ($keys as $key) { $this->setMessage($messageString, $key); } return $this; @@ -93,7 +93,7 @@ protected function _error($messageKey, $value = null) */ protected function _createMessage($messageKey, $value) { - if(!isset($this->_messageTemplates[$messageKey])){ + if (!isset($this->_messageTemplates[$messageKey])){ return null; } $message = $this->_messageTemplates[$messageKey]; From 9d9be7db95442cd4540d034a3b60c19c77afa2fa Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sun, 2 Apr 2017 23:34:48 +0200 Subject: [PATCH 11/13] Fix phpcs & phpmd warnings --- .../Magento/Framework/Validator/Email.php | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/internal/Magento/Framework/Validator/Email.php b/lib/internal/Magento/Framework/Validator/Email.php index 0868a9b3ede0b..94db3f36f09a5 100644 --- a/lib/internal/Magento/Framework/Validator/Email.php +++ b/lib/internal/Magento/Framework/Validator/Email.php @@ -16,7 +16,7 @@ class Email extends AbstractValidator implements \Magento\Framework\Validator\Va * * @var array */ - protected $_messageTemplates = [ + protected $messageTemplates = [ self::INVALID => '"%1" is not a valid email address.' ]; @@ -31,7 +31,7 @@ public function isValid($value) $isValid = true; if (!is_string($value) || strrpos($value, '@') === false) { $isValid = false; - $this->_error(self::INVALID, $value); + $this->error(self::INVALID, $value); } return $isValid; @@ -48,35 +48,37 @@ public function isValid($value) public function setMessage($messageString, $messageKey = null) { if ($messageKey === null) { - $keys = array_keys($this->_messageTemplates); + $keys = array_keys($this->messageTemplates); foreach ($keys as $key) { $this->setMessage($messageString, $key); } return $this; } - if (!isset($this->_messageTemplates[$messageKey])) { + if (!isset($this->messageTemplates[$messageKey])) { $exceptionPhrase = new \Magento\Framework\Phrase("No message template exists for key '$messageKey'"); throw new Exception($exceptionPhrase); } - $this->_messageTemplates[$messageKey] = $messageString; + $this->messageTemplates[$messageKey] = $messageString; return $this; } /** + * Handles errors, sets error messages + * * @param string $messageKey * @param string $value OPTIONAL * @return void */ - protected function _error($messageKey, $value = null) + protected function error($messageKey, $value = null) { if ($messageKey === null) { - $keys = array_keys($this->_messageTemplates); + $keys = array_keys($this->messageTemplates); $messageKey = current($keys); } - $this->_messages[$messageKey] = $this->_createMessage($messageKey, $value); + $this->_messages[$messageKey] = $this->createMessage($messageKey, $value); } /** @@ -91,12 +93,12 @@ protected function _error($messageKey, $value = null) * @param string $value * @return string */ - protected function _createMessage($messageKey, $value) + protected function createMessage($messageKey, $value) { - if (!isset($this->_messageTemplates[$messageKey])){ + if (!isset($this->messageTemplates[$messageKey])) { return null; } - $message = $this->_messageTemplates[$messageKey]; + $message = $this->messageTemplates[$messageKey]; $message = str_replace('%1', $value, $message); return $message; From 764f757381338839e2ddd34266357e24e22989e7 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Fri, 14 Apr 2017 13:47:21 +0200 Subject: [PATCH 12/13] Revert emailSender js validator change --- app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js index 5aa317596680c..dc927d6d9f233 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js @@ -428,7 +428,7 @@ define([ ], 'validate-emailSender': [ function (value) { - return utils.isEmptyNoTrim(value) || value.indexOf('@') !== -1; + return utils.isEmptyNoTrim(value) || /^[\S ]+$/.test(value); }, $.mage.__('Please enter a valid email address (Ex: johndoe@domain.com).') ], From 0095a1bf6a251041ffd69cc989adf2350dc0eea5 Mon Sep 17 00:00:00 2001 From: Petar Sambolek Date: Sat, 17 Jun 2017 00:13:33 +0200 Subject: [PATCH 13/13] Implement EmailMinimal validator, replace usages of old Email validator --- .../Model/Metadata/Form/AbstractData.php | 8 +- .../Eav/Model/Attribute/Data/AbstractData.php | 8 +- .../view/base/web/js/lib/validation/rules.js | 6 + .../User/Model/UserValidationRules.php | 6 +- .../Magento/Framework/Validator/Email.php | 106 ------------------ .../Framework/Validator/EmailAddress.php | 2 +- .../Framework/Validator/EmailMinimal.php | 89 +++++++++++++++ lib/web/jquery/jquery.validate.js | 3 +- lib/web/mage/validation.js | 10 +- 9 files changed, 113 insertions(+), 125 deletions(-) delete mode 100644 lib/internal/Magento/Framework/Validator/Email.php create mode 100644 lib/internal/Magento/Framework/Validator/EmailMinimal.php diff --git a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php index 7697ad42e4b6e..be3bf46275140 100644 --- a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php +++ b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php @@ -326,13 +326,9 @@ protected function _validateInputRule($value) /** __('"%1" is not a valid email address.') */ - $validator = new \Magento\Framework\Validator\Email(); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\Email::INVALID - ); + $validator = new \Magento\Framework\Validator\EmailMinimal(); if (!$validator->isValid($value)) { - return array_unique($validator->getMessages()); + return $validator->getMessages(); } break; case 'url': diff --git a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php index 8394f0502f85d..51156aeabe846 100644 --- a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php +++ b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php @@ -355,13 +355,9 @@ protected function _validateInputRule($value) /** __('"%1" is not a valid email address.') */ - $validator = new \Magento\Framework\Validator\Email(); - $validator->setMessage( - __('"%1" is not a valid email address.', $label), - \Magento\Framework\Validator\Email::INVALID - ); + $validator = new \Magento\Framework\Validator\EmailMinimal(); if (!$validator->isValid($value)) { - return array_unique($validator->getMessages()); + return $validator->getMessages(); } break; case 'url': diff --git a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js index dc927d6d9f233..bb85af3f8c8ea 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js @@ -254,6 +254,12 @@ define([ }, $.validator.messages.email ], + 'email-minimal': [ + function (value) { + return this.optional(element) || value.indexOf('@') !== -1; + }, + $.mage.__('Please enter a valid email address.') + ], 'url2': [ function (value) { return /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\u0027\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\u0027\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\u0027\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\u0027\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\u0027\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);//eslint-disable-line max-len diff --git a/app/code/Magento/User/Model/UserValidationRules.php b/app/code/Magento/User/Model/UserValidationRules.php index 93dc2254d0a7f..d69981060c6fd 100644 --- a/app/code/Magento/User/Model/UserValidationRules.php +++ b/app/code/Magento/User/Model/UserValidationRules.php @@ -5,7 +5,7 @@ */ namespace Magento\User\Model; -use Magento\Framework\Validator\Email; +use Magento\Framework\Validator\EmailMinimal; use Magento\Framework\Validator\NotEmpty; use Magento\Framework\Validator\Regex; use Magento\Framework\Validator\StringLength; @@ -36,8 +36,8 @@ public function addUserInfoRules(\Magento\Framework\Validator\DataObject $valida $firstNameNotEmpty->setMessage(__('First Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY); $lastNameNotEmpty = new NotEmpty(); $lastNameNotEmpty->setMessage(__('Last Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY); - $emailValidity = new Email(); - $emailValidity->setMessage(__('Please enter a valid email.'), \Magento\Framework\Validator\Email::INVALID); + $emailValidity = new EmailMinimal(); + $emailValidity->setMessage(__('Please enter a valid email.'), \Magento\Framework\Validator\EmailMinimal::INVALID); /** @var $validator \Magento\Framework\Validator\DataObject */ $validator->addRule( diff --git a/lib/internal/Magento/Framework/Validator/Email.php b/lib/internal/Magento/Framework/Validator/Email.php deleted file mode 100644 index 94db3f36f09a5..0000000000000 --- a/lib/internal/Magento/Framework/Validator/Email.php +++ /dev/null @@ -1,106 +0,0 @@ - '"%1" is not a valid email address.' - ]; - - /** - * Validate email address contains '@' sign - * - * @param mixed $value - * @return bool - */ - public function isValid($value) - { - $isValid = true; - if (!is_string($value) || strrpos($value, '@') === false) { - $isValid = false; - $this->error(self::INVALID, $value); - } - - return $isValid; - } - - /** - * Sets the validation failure message template for a particular key - * - * @param string $messageString - * @param string $messageKey OPTIONAL - * @return AbstractValidator Provides a fluent interface - * @throws Exception - */ - public function setMessage($messageString, $messageKey = null) - { - if ($messageKey === null) { - $keys = array_keys($this->messageTemplates); - foreach ($keys as $key) { - $this->setMessage($messageString, $key); - } - return $this; - } - - if (!isset($this->messageTemplates[$messageKey])) { - $exceptionPhrase = new \Magento\Framework\Phrase("No message template exists for key '$messageKey'"); - throw new Exception($exceptionPhrase); - } - - $this->messageTemplates[$messageKey] = $messageString; - return $this; - } - - /** - * Handles errors, sets error messages - * - * @param string $messageKey - * @param string $value OPTIONAL - * @return void - */ - protected function error($messageKey, $value = null) - { - if ($messageKey === null) { - $keys = array_keys($this->messageTemplates); - $messageKey = current($keys); - } - - $this->_messages[$messageKey] = $this->createMessage($messageKey, $value); - } - - /** - * Constructs and returns a validation failure message with the given message key and value. - * - * Returns null if and only if $messageKey does not correspond to an existing template. - * - * If a translator is available and a translation exists for $messageKey, - * the translation will be used. - * - * @param string $messageKey - * @param string $value - * @return string - */ - protected function createMessage($messageKey, $value) - { - if (!isset($this->messageTemplates[$messageKey])) { - return null; - } - $message = $this->messageTemplates[$messageKey]; - $message = str_replace('%1', $value, $message); - - return $message; - } -} diff --git a/lib/internal/Magento/Framework/Validator/EmailAddress.php b/lib/internal/Magento/Framework/Validator/EmailAddress.php index 7af04643b19b3..3adaa3ac4786e 100644 --- a/lib/internal/Magento/Framework/Validator/EmailAddress.php +++ b/lib/internal/Magento/Framework/Validator/EmailAddress.php @@ -7,7 +7,7 @@ */ /** * @deprecated - * @see \Magento\Framework\Validator\Email + * @see \Magento\Framework\Validator\EmailMinimal */ namespace Magento\Framework\Validator; diff --git a/lib/internal/Magento/Framework/Validator/EmailMinimal.php b/lib/internal/Magento/Framework/Validator/EmailMinimal.php new file mode 100644 index 0000000000000..f194dc3b7156c --- /dev/null +++ b/lib/internal/Magento/Framework/Validator/EmailMinimal.php @@ -0,0 +1,89 @@ + '"%1" is not a valid email address.' + ]; + + /** + * Validation error messages + * + * @var string[] Validation error messages + */ + private $messages = []; + + /** + * Validate email address contains '@' sign + * + * @param string $value + * + * @return bool + */ + public function isValid($value) + { + $this->messages = []; + if (!is_string($value) || strrpos($value, '@') === false) { + $translatedMessage = __($this->messageTemplates[self::INVALID], $value); + $this->messages[] = $translatedMessage; + } + + return empty($this->_messages); + } + + /** + * Return error messages (if any) after the last validation + * + * @return string[] + */ + public function getMessages() + { + return $this->messages; + } + + /** + * Sets the validation failure message template for a particular key + * + * @param string $messageString + * @param null $messageKey OPTIONAL + * + * @return $this + * @throws \InvalidArgumentException If no message template exists for key + */ + public function setMessage($messageString, $messageKey = null) + { + if ($messageKey === null) { + $keys = array_keys($this->messageTemplates); + foreach ($keys as $key) { + $this->setMessage($messageString, $key); + } + + return $this; + } + + if (!isset($this->messageTemplates[$messageKey])) { + throw new \InvalidArgumentException( + sprintf('No message template exists for key %s', $messageKey) + ); + } + + $this->messageTemplates[$messageKey] = $messageString; + + return $this; + } +} diff --git a/lib/web/jquery/jquery.validate.js b/lib/web/jquery/jquery.validate.js index 2a8d8eca81720..a7f85a23137a4 100644 --- a/lib/web/jquery/jquery.validate.js +++ b/lib/web/jquery/jquery.validate.js @@ -1113,8 +1113,7 @@ // http://docs.jquery.com/Plugins/Validation/Methods/email email: function (value, element) { // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ - // return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value); - return this.optional(element) || value.indexOf('@') !== -1; + return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/url diff --git a/lib/web/mage/validation.js b/lib/web/mage/validation.js index 26f3e4ebab967..f4f59a2ff41f5 100644 --- a/lib/web/mage/validation.js +++ b/lib/web/mage/validation.js @@ -401,8 +401,16 @@ return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value); }, - $.validator.messages.email + $.mage.__('Please enter a valid email address.') ], + + 'email-minimal': [ + function (value, element) { + return this.optional(element) || value.indexOf('@') !== -1; + }, + $.validator.messages.emailMinimal + ], + 'url2': [ function (value, element) { return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);