Normalize input to TitleParser::parseTitle()
authorAryeh Gregor <ayg@aryeh.name>
Mon, 15 Apr 2019 12:42:03 +0000 (15:42 +0300)
committerAryeh Gregor <ayg@aryeh.name>
Mon, 15 Apr 2019 14:08:59 +0000 (17:08 +0300)
This matches behavior of Title::newFromText(), which assists porting old
code to TitleParser.

Change-Id: I50e9af09df843ea575250e276c7cfce660c00efd

includes/title/MediaWikiTitleCodec.php
tests/phpunit/includes/title/MediaWikiTitleCodecTest.php

index adbea89..b2c8521 100644 (file)
@@ -149,10 +149,13 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
         * @return TitleValue
         */
        public function parseTitle( $text, $defaultNamespace = NS_MAIN ) {
+               // Convert things like &eacute; &#257; or &#x3017; into normalized (T16952) text
+               $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
+
                // NOTE: this is an ugly cludge that allows this class to share the
                // code for parsing with the old Title class. The parser code should
                // be refactored to avoid this.
-               $parts = $this->splitTitleString( $text, $defaultNamespace );
+               $parts = $this->splitTitleString( $filteredText, $defaultNamespace );
 
                // Relative fragment links are not supported by TitleValue
                if ( $parts['dbkey'] === '' ) {
index 20f0039..5e8bf66 100644 (file)
@@ -298,7 +298,9 @@ class MediaWikiTitleCodecTest extends MediaWikiTestCase {
                                new TitleValue( NS_CATEGORY,
                                        'X' . str_repeat( 'x', 247 ) ) ],
                        [ str_repeat( 'x', 252 ), NS_MAIN, 'en',
-                               'X' . str_repeat( 'x', 251 ) ]
+                               'X' . str_repeat( 'x', 251 ) ],
+                       // Test decoding and normalization
+                       [ '&quot;n&#x303;&#34;', NS_MAIN, 'en', new TitleValue( NS_MAIN, '"ñ"' ) ],
                ];
        }