Fix #6526: Undefined offset notice in MagicWord.php on bad input
authorAntoine Musso <hashar@users.mediawiki.org>
Tue, 11 Jul 2006 13:42:34 +0000 (13:42 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Tue, 11 Jul 2006 13:42:34 +0000 (13:42 +0000)
Filter first, check after.

includes/MagicWord.php

index 75a8413..c5b7502 100644 (file)
@@ -310,14 +310,16 @@ class MagicWord {
                $matchcount = preg_match( $this->getVariableStartToEndRegex(), $text, $matches );
                if ( $matchcount == 0 ) {
                        return NULL;
-               } elseif ( count($matches) == 1 ) {
-                       return $matches[0];
                } else {
                        # multiple matched parts (variable match); some will be empty because of
                        # synonyms. The variable will be the second non-empty one so remove any
                        # blank elements and re-sort the indices.
+                       # See also bug 6526
+
                        $matches = array_values(array_filter($matches));
-                       return $matches[1];
+
+                       if ( count($matches) == 1 ) { return $matches[0]; }
+                       else { return $matches[1]; }
                }
        }