Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/246719
Change subject: Throw Exceptions on preg_* failures in
MagicWordArray::matchAndRemove()
......................................................................
Throw Exceptions on preg_* failures in MagicWordArray::matchAndRemove()
There are a lot of other cases in this file alone that need to be fixed
(e.g. (bool)preg_match), but those should be fixed in a more systematic
way like a wrapper function.
Bug: T115514
Change-Id: I3840a56adc0a6e50963b930051892491f8e90245
---
M includes/MagicWord.php
1 file changed, 12 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/19/246719/1
diff --git a/includes/MagicWord.php b/includes/MagicWord.php
index 2c7ba91..424735e 100644
--- a/includes/MagicWord.php
+++ b/includes/MagicWord.php
@@ -941,6 +941,7 @@
*
* @param string $text
*
+ * @throws Exception
* @return array
*/
public function matchAndRemove( &$text ) {
@@ -951,13 +952,22 @@
continue;
}
$matches = array();
- if ( preg_match_all( $regex, $text, $matches,
PREG_SET_ORDER ) ) {
+ $matched = preg_match_all( $regex, $text, $matches,
PREG_SET_ORDER );
+ if ( $matched === false ) {
+ throw new Exception( __METHOD__ . ':
preg_match_all returned false' );
+ }
+ if ( $matched ) {
foreach ( $matches as $m ) {
list( $name, $param ) =
$this->parseMatch( $m );
$found[$name] = $param;
}
}
- $text = preg_replace( $regex, '', $text );
+ $replaced = preg_replace( $regex, '', $text );
+ if ( $replaced !== null ) {
+ $text = $replaced;
+ } else {
+ throw new Exception( __METHOD__ . ':
preg_replace returned null' );
+ }
}
return $found;
}
--
To view, visit https://gerrit.wikimedia.org/r/246719
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3840a56adc0a6e50963b930051892491f8e90245
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits