X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMagicWord.php;h=17c7cd491466c71b183fc0615c4f034a7dcd55b1;hb=ef7760a50d8a5c09e10a4f0f74ff943171f6c94f;hp=186821de394fd23458fe050c6589e6d94c95f037;hpb=ddffe4453958f13805a99e5bff58229d203c5ea5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 186821de39..17c7cd4914 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -718,9 +718,6 @@ class MagicWordArray { private $regex; - /** @todo Unused? */ - private $matches; - /** * @param array $names */ @@ -944,6 +941,7 @@ class MagicWordArray { * * @param string $text * + * @throws Exception * @return array */ public function matchAndRemove( &$text ) { @@ -953,12 +951,25 @@ class MagicWordArray { if ( $regex === '' ) { continue; } - preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ); - foreach ( $matches as $m ) { - list( $name, $param ) = $this->parseMatch( $m ); - $found[$name] = $param; + $matches = array(); + $matched = preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ); + if ( $matched === false ) { + throw new Exception( __METHOD__ . ': preg_match_all returned false with error code ' + . preg_last_error() ); + } + if ( $matched ) { + foreach ( $matches as $m ) { + list( $name, $param ) = $this->parseMatch( $m ); + $found[$name] = $param; + } + } + $replaced = preg_replace( $regex, '', $text ); + if ( $replaced !== null ) { + $text = $replaced; + } else { + throw new Exception( __METHOD__ . ': preg_replace returned null with error code ' + . preg_last_error() ); } - $text = preg_replace( $regex, '', $text ); } return $found; }