if( !wfRunHooks( 'isValidEmailAddr', array( $addr, &$result ) ) ) {
return $result;
}
- $rfc5322_atext = "a-z0-9!#$%&'*+-\/=?^_`{|}~" ;
- $rfc1034_ldh_str = "a-z0-9-" ;
+
+ // Please note strings below are enclosed in brackets [], this make the
+ // hyphen "-" a range indicator. Hence it is double backslashed below.
+ // See bug 26948
+ $rfc5322_atext = "a-z0-9!#$%&'*+\\-\/=?^_`{|}~" ;
+ $rfc1034_ldh_str = "a-z0-9\\-" ;
$HTML5_email_regexp = "/
^ # start of string
"|" / "}" /
"~"
*/
- var rfc5322_atext = "a-z0-9!#$%&'*+-/=?^_`{|}~",
+ var rfc5322_atext = "a-z0-9!#$%&'*+\\-/=?^_`{|}~",
/**
* Next define the RFC 1034 'ldh-str'
* <let-dig-hyp> ::= <let-dig> | "-"
* <let-dig> ::= <letter> | <digit>
*/
- rfc1034_ldh_str = "a-z0-9-",
+ var rfc1034_ldh_str = "a-z0-9\\-",
HTML5_email_regexp = new RegExp(
// start of string
'^'
+
// User part which is liberal :p
- '[' + rfc5322_atext + '\\.' + ']' + '+'
+ '[' + rfc5322_atext + '\\.]+'
+
// 'at'
'@'
mw.test.addTest( 'mw.util.validateEmail( "user@localhost" )',
'true (boolean)' );
+ // testEmailWithCommasAreInvalids
+ mw.test.addTest( 'mw.util.validateEmail( "user,foo@example.org" )',
+ 'false (boolean)' );
+ mw.test.addTest( 'mw.util.validateEmail( "userfoo@ex,ample.org" )',
+ 'false (boolean)' );
+ // testEmailWithHyphens
+ mw.test.addTest( 'mw.util.validateEmail( "user-foo@example.org" )',
+ 'true (boolean)' );
+ mw.test.addTest( 'mw.util.validateEmail( "userfoo@ex-ample.org" )',
+ 'true (boolean)' );
+
// jQuery plugins
mw.test.addHead( 'jQuery plugins' );
$this->invalid( "first last@mycompany" );
$this->invalid( "firstlast@my company" );
}
+ // bug 26948 : comma were matched by an incorrect regexp range
+ function testEmailWithCommasAreInvalids() {
+ $this->invalid( "user,foo@example.org" );
+ $this->invalid( "userfoo@ex,ample.org" );
+ }
+ function testEmailWithHyphens() {
+ $this->valid( "user-foo@example.org" );
+ $this->valid( "userfoo@ex-ample.org" );
+ }
function testEmailDomainCanNotBeginWithDot() {
$this->invalid( "user@." );
$this->invalid( "user@.localdomain" );