r102486 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102485‎ | r102486 | r102487 >
Date:02:56, 9 November 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_URI.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/RELEASE-NOTES
@@ -19,6 +19,7 @@
2020 * Fixed hide query functionality on Special:Ask (bug 30768).
2121 * Fixed display of internal SMW helper constants in certain queries (bug 30969).
2222 * Fixed some issues with the category result format (including bug 30761).
 23+* Fixed email validation issue (bug 32295).
2324 * Dropped compatibility with old-style (SMW < 1.6) query printers.
2425
2526 == SMW 1.6.1 ==
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_URI.php
@@ -128,9 +128,9 @@
129129 $value = substr( $value, 7 );
130130 $this->m_wikitext = $value;
131131 }
132 - /// TODO The following is too strict, since emails may contain non-ASCII symbols (by RFC 2047 and RFC 3490)
133 - $check = "#^([_a-zA-Z0-9-]+)((\.[_a-zA-Z0-9-]+)*)@([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*)\.([a-zA-Z]{2,6})$#u";
134 - if ( !preg_match( $check, $value ) ) {
 132+
 133+ $check = method_exists( 'Sanitizer', 'validateEmail' ) ? Sanitizer::validateEmail( $value ) : self::validateEmail( $value );
 134+ if ( !$check ) {
135135 ///TODO: introduce error-message for "bad" email
136136 $this->addError( wfMsgForContent( 'smw_baduri', $value ) );
137137 break;
@@ -255,6 +255,35 @@
256256
257257 return '';
258258 }
 259+
 260+ /**
 261+ * This is a copy of
 262+ * @see Sanitizer::validateEmail
 263+ * which was introduced in MW 1.18, and is thus used for compatibility with earlier versions.
 264+ */
 265+ public static function validateEmail( $addr ) {
 266+ $result = null;
 267+ if( !wfRunHooks( 'isValidEmailAddr', array( $addr, &$result ) ) ) {
 268+ return $result;
 269+ }
259270
 271+ // Please note strings below are enclosed in brackets [], this make the
 272+ // hyphen "-" a range indicator. Hence it is double backslashed below.
 273+ // See bug 26948
 274+ $rfc5322_atext = "a-z0-9!#$%&'*+\\-\/=?^_`{|}~" ;
 275+ $rfc1034_ldh_str = "a-z0-9\\-" ;
 276+
 277+ $HTML5_email_regexp = "/
 278+ ^ # start of string
 279+ [$rfc5322_atext\\.]+ # user part which is liberal :p
 280+ @ # 'apostrophe'
 281+ [$rfc1034_ldh_str]+ # First domain part
 282+ (\\.[$rfc1034_ldh_str]+)* # Following part prefixed with a dot
 283+ $ # End of string
 284+ /ix" ; // case Insensitive, eXtended
 285+
 286+ return (bool) preg_match( $HTML5_email_regexp, $addr );
 287+ }
 288+
260289 }
261290

Status & tagging log