Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/247934
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, 10 insertions(+), 46 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter
refs/changes/34/247934/1
diff --git a/AbuseFilter.parser.php b/AbuseFilter.parser.php
index 447166f..8a0d0fb 100644
--- a/AbuseFilter.parser.php
+++ b/AbuseFilter.parser.php
@@ -287,14 +287,14 @@
$pattern .= 'i';
}
- $handler = new AFPRegexErrorHandler( $pattern, $pos );
try {
- $handler->install();
$result = preg_match( $pattern, $str );
- $handler->restore();
} catch ( Exception $e ) {
- $handler->restore();
- throw $e;
+ throw new AFPUserVisibleException(
+ 'regexfailure',
+ 0, // current position not known in static
context
+ array( (string) $e, $str, $pattern )
+ );
}
return new AFPData( self::DBool, (bool)$result );
}
@@ -550,41 +550,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 +1529,14 @@
$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;
+ throw new AFPUserVisibleException(
+ 'regexfailure',
+ $this->mCur->pos,
+ array( (string) $e, $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: newchange
Gerrit-Change-Id: Ice1b6da433b892d9871780a9753c098aa639bf6c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits