jenkins-bot has submitted this change and it was merged.

Change subject: AbuseFilter: don't install custom error handler
......................................................................


AbuseFilter: don't install custom error handler

Scrap the AFPRegexErrorHandler custom error handler clusterfuck and replace it
with a simple try-catch that accomplishes the same thing.

Change-Id: Ice1b6da433b892d9871780a9753c098aa639bf6c
---
M AbuseFilter.parser.php
M AbuseFilter.php
2 files changed, 14 insertions(+), 52 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/AbuseFilter.parser.php b/AbuseFilter.parser.php
index 447166f..e628177 100644
--- a/AbuseFilter.parser.php
+++ b/AbuseFilter.parser.php
@@ -287,14 +287,13 @@
                        $pattern .= 'i';
                }
 
-               $handler = new AFPRegexErrorHandler( $pattern, $pos );
-               try {
-                       $handler->install();
-                       $result = preg_match( $pattern, $str );
-                       $handler->restore();
-               } catch ( Exception $e ) {
-                       $handler->restore();
-                       throw $e;
+               $result = preg_match( $pattern, $str );
+               if ( $result === false ) {
+                       throw new AFPUserVisibleException(
+                               'regexfailure',
+                               $pos,
+                               array( 'unspecified error in preg_match()', 
$pattern )
+                       );
                }
                return new AFPData( self::DBool, (bool)$result );
        }
@@ -550,41 +549,6 @@
                $this->mExceptionID = $exception_id;
                $this->mPosition = $position;
                $this->mParams = $params;
-       }
-}
-
-class AFPRegexErrorHandler {
-       function __construct( $regex, $pos ) {
-               $this->regex = $regex;
-               $this->pos = $pos;
-       }
-
-       /**
-        * @param $errno
-        * @param $errstr
-        * @param $errfile
-        * @param $errline
-        * @param $context
-        * @return bool
-        * @throws AFPUserVisibleException
-        */
-       function handleError( $errno, $errstr, $errfile, $errline, $context ) {
-               if ( error_reporting() == 0 ) {
-                       return true;
-               }
-               throw new AFPUserVisibleException(
-                       'regexfailure',
-                       $this->pos,
-                       array( $errstr, $this->regex )
-               );
-       }
-
-       function install() {
-               set_error_handler( array( $this, 'handleError' ) );
-       }
-
-       function restore() {
-               restore_error_handler();
        }
 }
 
@@ -1564,14 +1528,13 @@
 
                        $matches = array();
 
-                       $handler = new AFPRegexErrorHandler( $needle, 
$this->mCur->pos );
-                       try {
-                               $handler->install();
-                               $count = preg_match_all( $needle, $haystack, 
$matches );
-                               $handler->restore();
-                       } catch ( Exception $e ) {
-                               $handler->restore();
-                               throw $e;
+                       $count = preg_match_all( $needle, $haystack, $matches );
+                       if ( $count === false ) {
+                               throw new AFPUserVisibleException(
+                                       'regexfailure',
+                                       $this->mCur->pos,
+                                       array( 'unspecified error in 
preg_match_all()', $needle )
+                               );
                        }
                }
 
diff --git a/AbuseFilter.php b/AbuseFilter.php
index c0fce42..33f5c0d 100644
--- a/AbuseFilter.php
+++ b/AbuseFilter.php
@@ -59,7 +59,6 @@
 $wgAutoloadClasses['AFPData'] = "$dir/AbuseFilter.parser.php";
 $wgAutoloadClasses['AFPException'] = "$dir/AbuseFilter.parser.php";
 $wgAutoloadClasses['AFPParserState'] = "$dir/AbuseFilter.parser.php";
-$wgAutoloadClasses['AFPRegexErrorHandler'] = "$dir/AbuseFilter.parser.php";
 $wgAutoloadClasses['AFPToken'] = "$dir/AbuseFilter.parser.php";
 $wgAutoloadClasses['AFPUserVisibleException'] = "$dir/AbuseFilter.parser.php";
 

-- 
To view, visit https://gerrit.wikimedia.org/r/247934
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ice1b6da433b892d9871780a9753c098aa639bf6c
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Se4598 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to