{{anchorencode:}} output should be always usable in links
authorMax Semenik <maxsem.wiki@gmail.com>
Mon, 13 Nov 2017 23:53:24 +0000 (15:53 -0800)
committerC. Scott Ananian <cscott@cscott.net>
Tue, 21 Nov 2017 21:42:35 +0000 (16:42 -0500)
Bug: T179544

Change-Id: If8098e3e839e8ba1cf27b6053017e818c556a733

includes/parser/CoreParserFunctions.php
tests/parser/parserTests.txt

index bb0072c..07944d4 100644 (file)
@@ -930,7 +930,8 @@ class CoreParserFunctions {
         */
        public static function anchorencode( $parser, $text ) {
                $text = $parser->killMarkers( $text );
-               return (string)substr( $parser->guessSectionNameFromWikiText( $text ), 1 );
+               $section = (string)substr( $parser->guessSectionNameFromWikiText( $text ), 1 );
+               return Sanitizer::safeEncodeAttribute( $section );
        }
 
        public static function special( $parser, $text ) {
index 6e9f944..c3cea04 100644 (file)
@@ -29729,3 +29729,14 @@ T72875: Test for brackets in attributes of elements in internal link texts
 <a href="/wiki/Foo" title="Foo">link <span title="title with &#91;&#91;double brackets&#93;&#93;">span</span></a>
 </p>
 !! end
+
+!! test
+T179544: {{anchorencode:}} output should be always usable in links
+!! config
+wgFragmentMode=[ 'html5' ]
+!! wikitext
+<span id="{{anchorencode:[foo]}}"></span>[[#{{anchorencode:[foo]}}]]
+!! html/php
+<p><span id="&#91;foo&#93;"></span><a href="#[foo]">#&#91;foo&#93;</a>
+</p>
+!! end