Merge "Fix MWDebugTest::testAppendDebugInfoToApiResultXmlFormat"
[lhc/web/wiklou.git] / includes / parser / Parser.php
index f2e47dc..ea58acc 100644 (file)
@@ -3944,7 +3944,7 @@ class Parser {
                        $this->mForceTocPosition = true;
 
                        # Set a placeholder. At the end we'll fill it in with the TOC.
-                       $text = $mw->replace( '<!--MWTOC-->', $text, 1 );
+                       $text = $mw->replace( '<!--MWTOC\'"-->', $text, 1 );
 
                        # Only keep the first one.
                        $text = $mw->replace( '', $text );
@@ -4206,6 +4206,9 @@ class Parser {
 
                        # Decode HTML entities
                        $safeHeadline = Sanitizer::decodeCharReferences( $safeHeadline );
+
+                       $safeHeadline = $this->normalizeSectionName( $safeHeadline );
+
                        $fallbackHeadline = Sanitizer::escapeIdForAttribute( $safeHeadline, Sanitizer::ID_FALLBACK );
                        $linkAnchor = Sanitizer::escapeIdForLink( $safeHeadline );
                        $safeHeadline = Sanitizer::escapeIdForAttribute( $safeHeadline, Sanitizer::ID_PRIMARY );
@@ -4387,7 +4390,7 @@ class Parser {
                $full .= implode( '', $sections );
 
                if ( $this->mForceTocPosition ) {
-                       return str_replace( '<!--MWTOC-->', $toc, $full );
+                       return str_replace( '<!--MWTOC\'"-->', $toc, $full );
                } else {
                        return $full;
                }
@@ -5767,6 +5770,8 @@ class Parser {
                $text = $this->stripSectionName( $text );
                $text = Sanitizer::normalizeSectionNameWhitespace( $text );
                $text = Sanitizer::decodeCharReferences( $text );
+               $text = $this->normalizeSectionName( $text );
+
                return '#' . Sanitizer::escapeIdForLink( $text );
        }
 
@@ -5786,6 +5791,7 @@ class Parser {
                $text = $this->stripSectionName( $text );
                $text = Sanitizer::normalizeSectionNameWhitespace( $text );
                $text = Sanitizer::decodeCharReferences( $text );
+               $text = $this->normalizeSectionName( $text );
 
                if ( isset( $wgFragmentMode[1] ) && $wgFragmentMode[1] === 'legacy' ) {
                        // ForAttribute() and ForLink() are the same for legacy encoding
@@ -5797,6 +5803,24 @@ class Parser {
                return "#$id";
        }
 
+       /**
+        * Apply the same normalization as code making links to this section would
+        *
+        * @param string $text
+        * @return string
+        */
+       private function normalizeSectionName( $text ) {
+               # T90902: ensure the same normalization is applied for IDs as to links
+               $titleParser = MediaWikiServices::getInstance()->getTitleParser();
+               try {
+
+                       $parts = $titleParser->splitTitleString( "#$text" );
+               } catch ( MalformedTitleException $ex ) {
+                       return $text;
+               }
+               return $parts['fragment'];
+       }
+
        /**
         * Strips a text string of wikitext for use in a section anchor
         *