Index: trunk/extensions/SemanticMediaWiki/RELEASE-NOTES |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | * Fixed hide query functionality on Special:Ask (bug 30768). |
21 | 21 | * Fixed display of internal SMW helper constants in certain queries (bug 30969). |
22 | 22 | * Fixed some issues with the category result format (including bug 30761). |
| 23 | +* Fixed email validation issue (bug 32295). |
23 | 24 | * Dropped compatibility with old-style (SMW < 1.6) query printers. |
24 | 25 | |
25 | 26 | == SMW 1.6.1 == |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_URI.php |
— | — | @@ -128,9 +128,9 @@ |
129 | 129 | $value = substr( $value, 7 ); |
130 | 130 | $this->m_wikitext = $value; |
131 | 131 | } |
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 ) { |
135 | 135 | ///TODO: introduce error-message for "bad" email |
136 | 136 | $this->addError( wfMsgForContent( 'smw_baduri', $value ) ); |
137 | 137 | break; |
— | — | @@ -255,6 +255,35 @@ |
256 | 256 | |
257 | 257 | return ''; |
258 | 258 | } |
| 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 | + } |
259 | 270 | |
| 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 | + |
260 | 289 | } |
261 | 290 | |