From 5cbe54fa7b01e266effd22cf0ff9694a38565e46 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 27 Mar 2008 00:00:25 +0000 Subject: [PATCH] * (bug 13522) Fix fatal error in Parser::extractTagsAndParams Patch by MinuteElectron - https://bugzilla.wikimedia.org/attachment.cgi?id=4772 with fixes Replaces an instance variable with a constant, since it doesn't change, which is safe to access when the function is called statically from an outside class, as some extensions do. --- RELEASE-NOTES | 1 + includes/Parser.php | 22 ++++++++++++---------- includes/Preprocessor_DOM.php | 2 +- includes/Preprocessor_Hash.php | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 67553f0eb4..ba245a17c1 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -136,6 +136,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Trackback display formatting fixed * Don't die when single-element arrays are passed to SQL query constructors that have an array index other than 0 +* (bug 13522) Fix fatal error in Parser::extractTagsAndParams === API changes in 1.13 === diff --git a/includes/Parser.php b/includes/Parser.php index 5fb7b34c59..dfd43b6e63 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -82,14 +82,17 @@ class Parser const OT_WIKI = 2; const OT_PREPROCESS = 3; const OT_MSG = 3; - + + // Marker Suffix needs to be accessible staticly. + const MARKER_SUFFIX = "-QINU\x7f"; + /**#@+ * @private */ # Persistent: var $mTagHooks, $mTransparentTagHooks, $mFunctionHooks, $mFunctionSynonyms, $mVariables, - $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerSuffix, $mMarkerIndex, - $mExtLinkBracketedRegex, $mPreprocessor, $mDefaultStripList, $mVarCache, $mConf; + $mImageParams, $mImageParamsMagicArray, $mStripList, $mMarkerIndex, $mPreprocessor, + $mExtLinkBracketedRegex, $mDefaultStripList, $mVarCache, $mConf; # Cleared with clearState(): @@ -124,7 +127,6 @@ class Parser $this->mFunctionHooks = array(); $this->mFunctionSynonyms = array( 0 => array(), 1 => array() ); $this->mDefaultStripList = $this->mStripList = array( 'nowiki', 'gallery' ); - $this->mMarkerSuffix = "-QINU\x7f"; $this->mExtLinkBracketedRegex = '/\[(\b(' . wfUrlProtocols() . ')'. '[^][<>"\\x00-\\x20\\x7F]+) *([^\]\\x0a\\x0d]*?)\]/S'; $this->mVarCache = array(); @@ -526,7 +528,7 @@ class Parser $inside = $p[4]; } - $marker = "$uniq_prefix-$element-" . sprintf('%08X', $n++) . $this->mMarkerSuffix; + $marker = "$uniq_prefix-$element-" . sprintf('%08X', $n++) . self::MARKER_SUFFIX; $stripped .= $marker; if ( $close === '/>' ) { @@ -618,7 +620,7 @@ class Parser * @private */ function insertStripItem( $text ) { - $rnd = "{$this->mUniqPrefix}-item-{$this->mMarkerIndex}-{$this->mMarkerSuffix}"; + $rnd = "{$this->mUniqPrefix}-item-{$this->mMarkerIndex}-" . self::MARKER_SUFFIX; $this->mMarkerIndex++; $this->mStripState->general->setPair( $rnd, $text ); return $rnd; @@ -3185,7 +3187,7 @@ class Parser $attrText = !isset( $params['attr'] ) ? null : $frame->expand( $params['attr'] ); $content = !isset( $params['inner'] ) ? null : $frame->expand( $params['inner'] ); - $marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $this->mMarkerIndex++) . $this->mMarkerSuffix; + $marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $this->mMarkerIndex++) . self::MARKER_SUFFIX; if ( $this->ot['html'] ) { $name = strtolower( $name ); @@ -3378,7 +3380,7 @@ class Parser $prevlevel = 0; $toclevel = 0; $prevtoclevel = 0; - $markerRegex = "{$this->mUniqPrefix}-h-(\d+)-{$this->mMarkerSuffix}"; + $markerRegex = "{$this->mUniqPrefix}-h-(\d+)-" . self::MARKER_SUFFIX; $baseTitleText = $this->mTitle->getPrefixedDBkey(); $tocraw = array(); @@ -4822,12 +4824,12 @@ class Parser break; } else { $out .= call_user_func( $callback, substr( $s, $i, $markerStart - $i ) ); - $markerEnd = strpos( $s, $this->mMarkerSuffix, $markerStart ); + $markerEnd = strpos( $s, self::MARKER_SUFFIX, $markerStart ); if ( $markerEnd === false ) { $out .= substr( $s, $markerStart ); break; } else { - $markerEnd += strlen( $this->mMarkerSuffix ); + $markerEnd += strlen( self::MARKER_SUFFIX ); $out .= substr( $s, $markerStart, $markerEnd - $markerStart ); $i = $markerEnd; } diff --git a/includes/Preprocessor_DOM.php b/includes/Preprocessor_DOM.php index f17d70430b..526bd71f1a 100644 --- a/includes/Preprocessor_DOM.php +++ b/includes/Preprocessor_DOM.php @@ -979,7 +979,7 @@ class PPFrame_DOM implements PPFrame { $titleText = $this->title->getPrefixedDBkey(); $this->parser->mHeadings[] = array( $titleText, $headingIndex ); $serial = count( $this->parser->mHeadings ) - 1; - $marker = "{$this->parser->mUniqPrefix}-h-$serial-{$this->parser->mMarkerSuffix}"; + $marker = "{$this->parser->mUniqPrefix}-h-$serial-" . Parser::MARKER_SUFFIX; $count = $contextNode->getAttribute( 'level' ); $s = substr( $s, 0, $count ) . $marker . substr( $s, $count ); $this->parser->mStripState->general->setPair( $marker, '' ); diff --git a/includes/Preprocessor_Hash.php b/includes/Preprocessor_Hash.php index 85e152cb9c..85790982f4 100644 --- a/includes/Preprocessor_Hash.php +++ b/includes/Preprocessor_Hash.php @@ -928,7 +928,7 @@ class PPFrame_Hash implements PPFrame { $titleText = $this->title->getPrefixedDBkey(); $this->parser->mHeadings[] = array( $titleText, $bits['i'] ); $serial = count( $this->parser->mHeadings ) - 1; - $marker = "{$this->parser->mUniqPrefix}-h-$serial-{$this->parser->mMarkerSuffix}"; + $marker = "{$this->parser->mUniqPrefix}-h-$serial-" . Parser::MARKER_SUFFIX; $s = substr( $s, 0, $bits['level'] ) . $marker . substr( $s, $bits['level'] ); $this->parser->mStripState->general->setPair( $marker, '' ); $out .= $s; -- 2.20.1