Index: trunk/phase3/includes/User.php |
— | — | @@ -687,29 +687,10 @@ |
688 | 688 | * |
689 | 689 | * @param $addr String E-mail address |
690 | 690 | * @return Bool |
| 691 | + * @deprecated since 1.18 call Sanitizer::isValidEmail() directly |
691 | 692 | */ |
692 | 693 | public static function isValidEmailAddr( $addr ) { |
693 | | - $result = null; |
694 | | - if( !wfRunHooks( 'isValidEmailAddr', array( $addr, &$result ) ) ) { |
695 | | - return $result; |
696 | | - } |
697 | | - |
698 | | - // Please note strings below are enclosed in brackets [], this make the |
699 | | - // hyphen "-" a range indicator. Hence it is double backslashed below. |
700 | | - // See bug 26948 |
701 | | - $rfc5322_atext = "a-z0-9!#$%&'*+\\-\/=?^_`{|}~" ; |
702 | | - $rfc1034_ldh_str = "a-z0-9\\-" ; |
703 | | - |
704 | | - $HTML5_email_regexp = "/ |
705 | | - ^ # start of string |
706 | | - [$rfc5322_atext\\.]+ # user part which is liberal :p |
707 | | - @ # 'apostrophe' |
708 | | - [$rfc1034_ldh_str]+ # First domain part |
709 | | - (\\.[$rfc1034_ldh_str]+)* # Following part prefixed with a dot |
710 | | - $ # End of string |
711 | | - /ix" ; // case Insensitive, eXtended |
712 | | - |
713 | | - return (bool) preg_match( $HTML5_email_regexp, $addr ); |
| 694 | + return Sanitizer::isValidEmail( $addr ); |
714 | 695 | } |
715 | 696 | |
716 | 697 | /** |
Index: trunk/phase3/includes/Sanitizer.php |
— | — | @@ -1569,4 +1569,54 @@ |
1570 | 1570 | static function cleanUrlCallback( $matches ) { |
1571 | 1571 | return urlencode( $matches[0] ); |
1572 | 1572 | } |
| 1573 | + |
| 1574 | + /** |
| 1575 | + * Does a string look like an e-mail address? |
| 1576 | + * |
| 1577 | + * This validates an email address using an HTML5 specification found at: |
| 1578 | + * http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address |
| 1579 | + * Which as of 2011-01-24 says: |
| 1580 | + * |
| 1581 | + * A valid e-mail address is a string that matches the ABNF production |
| 1582 | + * 1*( atext / "." ) "@" ldh-str *( "." ldh-str ) where atext is defined |
| 1583 | + * in RFC 5322 section 3.2.3, and ldh-str is defined in RFC 1034 section |
| 1584 | + * 3.5. |
| 1585 | + * |
| 1586 | + * This function is an implementation of the specification as requested in |
| 1587 | + * bug 22449. |
| 1588 | + * |
| 1589 | + * Client-side forms will use the same standard validation rules via JS or |
| 1590 | + * HTML 5 validation; additional restrictions can be enforced server-side |
| 1591 | + * by extensions via the 'isValidEmailAddr' hook. |
| 1592 | + * |
| 1593 | + * Note that this validation doesn't 100% match RFC 2822, but is believed |
| 1594 | + * to be liberal enough for wide use. Some invalid addresses will still |
| 1595 | + * pass validation here. |
| 1596 | + * |
| 1597 | + * @param $addr String E-mail address |
| 1598 | + * @return Bool |
| 1599 | + */ |
| 1600 | + public static function validateEmail( $addr ) { |
| 1601 | + $result = null; |
| 1602 | + if( !wfRunHooks( 'isValidEmailAddr', array( $addr, &$result ) ) ) { |
| 1603 | + return $result; |
| 1604 | + } |
| 1605 | + |
| 1606 | + // Please note strings below are enclosed in brackets [], this make the |
| 1607 | + // hyphen "-" a range indicator. Hence it is double backslashed below. |
| 1608 | + // See bug 26948 |
| 1609 | + $rfc5322_atext = "a-z0-9!#$%&'*+\\-\/=?^_`{|}~" ; |
| 1610 | + $rfc1034_ldh_str = "a-z0-9\\-" ; |
| 1611 | + |
| 1612 | + $HTML5_email_regexp = "/ |
| 1613 | + ^ # start of string |
| 1614 | + [$rfc5322_atext\\.]+ # user part which is liberal :p |
| 1615 | + @ # 'apostrophe' |
| 1616 | + [$rfc1034_ldh_str]+ # First domain part |
| 1617 | + (\\.[$rfc1034_ldh_str]+)* # Following part prefixed with a dot |
| 1618 | + $ # End of string |
| 1619 | + /ix" ; // case Insensitive, eXtended |
| 1620 | + |
| 1621 | + return (bool) preg_match( $HTML5_email_regexp, $addr ); |
| 1622 | + } |
1573 | 1623 | } |