r86364 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86363‎ | r86364 | r86365 >
Date:23:16, 18 April 2011
Author:happy-melon
Status:ok (Comments)
Tags:
Comment:
Move User::isValidEmailAddr() to Sanitizer.
Modified paths:
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -687,29 +687,10 @@
688688 *
689689 * @param $addr String E-mail address
690690 * @return Bool
 691+ * @deprecated since 1.18 call Sanitizer::isValidEmail() directly
691692 */
692693 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 );
714695 }
715696
716697 /**
Index: trunk/phase3/includes/Sanitizer.php
@@ -1569,4 +1569,54 @@
15701570 static function cleanUrlCallback( $matches ) {
15711571 return urlencode( $matches[0] );
15721572 }
 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+ }
15731623 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r86366Follow-up r86364: Ctrl-S fail.happy-melon23:18, 18 April 2011
r90843Update calls to deprecated User::isValidEmailAddr...reedy19:16, 26 June 2011

Comments

#Comment by Krinkle (talk | contribs)   19:47, 26 June 2011

r 90843

#Comment by Krinkle (talk | contribs)   20:29, 26 June 2011

Reedy fixed the deprecated uses of it in trunk in r90843. See also "isValidEmailAddr" in trunk for more mentions of it.

Status & tagging log