Index: branches/wmf/1.18wmf1/extensions/AbuseFilter/AbuseFilter.parser.php |
— | — | @@ -216,12 +216,13 @@ |
217 | 217 | $pattern .= 'i'; |
218 | 218 | } |
219 | 219 | |
| 220 | + $handler = new AFPRegexErrorHandler( $pattern, $pos ); |
220 | 221 | try { |
221 | | - set_error_handler( array( 'AbuseFilterParser', 'regexErrorHandler' ) ); |
| 222 | + $handler->install(); |
222 | 223 | $result = preg_match( $pattern, $str ); |
223 | | - restore_error_handler(); |
| 224 | + $handler->restore(); |
224 | 225 | } catch ( Exception $e ) { |
225 | | - restore_error_handler(); |
| 226 | + $handler->restore(); |
226 | 227 | throw $e; |
227 | 228 | } |
228 | 229 | return new AFPData( self::DBool, (bool)$result ); |
— | — | @@ -381,6 +382,32 @@ |
382 | 383 | } |
383 | 384 | } |
384 | 385 | |
| 386 | +class AFPRegexErrorHandler { |
| 387 | + function __construct( $regex, $pos ) { |
| 388 | + $this->regex = $regex; |
| 389 | + $this->pos = $pos; |
| 390 | + } |
| 391 | + |
| 392 | + function handleError( $errno, $errstr, $errfile, $errline, $context ) { |
| 393 | + if ( error_reporting() == 0 ) { |
| 394 | + return true; |
| 395 | + } |
| 396 | + throw new AFPUserVisibleException( |
| 397 | + 'regexfailure', |
| 398 | + $this->pos, |
| 399 | + array( $errstr, $this->regex ) |
| 400 | + ); |
| 401 | + } |
| 402 | + |
| 403 | + function install() { |
| 404 | + set_error_handler( array( $this, 'handleError' ) ); |
| 405 | + } |
| 406 | + |
| 407 | + function restore() { |
| 408 | + restore_error_handler(); |
| 409 | + } |
| 410 | +} |
| 411 | + |
385 | 412 | class AbuseFilterParser { |
386 | 413 | var $mParams, $mVars, $mCode, $mTokens, $mPos, $mCur, $mShortCircuit, $mAllowShort; |
387 | 414 | |
— | — | @@ -1453,12 +1480,13 @@ |
1454 | 1481 | |
1455 | 1482 | $matches = array(); |
1456 | 1483 | |
| 1484 | + $handler = new AFPRegexErrorHandler( $needle, $this->mCur->pos ); |
1457 | 1485 | try { |
1458 | | - set_error_handler( array( 'AbuseFilterParser', 'regexErrorHandler' ) ); |
| 1486 | + $handler->install(); |
1459 | 1487 | $count = preg_match_all( $needle, $haystack, $matches ); |
1460 | | - restore_error_handler(); |
| 1488 | + $handler->restore(); |
1461 | 1489 | } catch ( Exception $e ) { |
1462 | | - restore_error_handler(); |
| 1490 | + $handler->restore(); |
1463 | 1491 | throw $e; |
1464 | 1492 | } |
1465 | 1493 | } |
— | — | @@ -1742,17 +1770,6 @@ |
1743 | 1771 | |
1744 | 1772 | return AFPData::castTypes( $val, AFPData::DBool ); |
1745 | 1773 | } |
1746 | | - |
1747 | | - public static function regexErrorHandler( $errno, $errstr, $errfile, $errline, $context ) { |
1748 | | - if ( error_reporting() == 0 ) { |
1749 | | - return true; |
1750 | | - } |
1751 | | - throw new AFPUserVisibleException( |
1752 | | - 'regexfailure', |
1753 | | - $context['pos'], |
1754 | | - array( $errstr, $context['regex'] ) |
1755 | | - ); |
1756 | | - } |
1757 | 1774 | } |
1758 | 1775 | |
1759 | 1776 | # Taken from http://au2.php.net/manual/en/function.fnmatch.php#71725 |