Revert throwing exceptions on preg_* failures
authorGergő Tisza <tgr.huwiki@gmail.com>
Thu, 29 Oct 2015 21:52:44 +0000 (14:52 -0700)
committerGergő Tisza <tgr.huwiki@gmail.com>
Thu, 29 Oct 2015 21:52:44 +0000 (14:52 -0700)
This reverts I3840a56adc0a6e50963b930051892491f8e90245 which
threw exceptions on broken UTF-8 in $text.

Bug: T115514
Bug: T117066
Change-Id: Ie665056a13f9e3678a49790d787b0a41dbba6362

includes/MagicWord.php

index 17c7cd4..2c7ba91 100644 (file)
@@ -941,7 +941,6 @@ class MagicWordArray {
         *
         * @param string $text
         *
-        * @throws Exception
         * @return array
         */
        public function matchAndRemove( &$text ) {
@@ -952,24 +951,13 @@ class MagicWordArray {
                                continue;
                        }
                        $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 ) {
+                       if ( preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ) ) {
                                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;
        }