Recognize CSS/JS redirects with non-ASCII targets
authorKunal Mehta <legoktm@member.fsf.org>
Tue, 30 Oct 2018 02:30:59 +0000 (19:30 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Thu, 1 Nov 2018 06:09:50 +0000 (23:09 -0700)
The regex in JavaScriptContent and CssContent was trying to pass
urlencoded stuff to Title::newFromText(), which would fail. Make sure we
urldecode it first.

Bug: T208264
Change-Id: I189c4c308da2875839ad8c1061332500f0e6d244

includes/content/CssContent.php
includes/content/JavaScriptContent.php
tests/phpunit/includes/content/CssContentHandlerTest.php
tests/phpunit/includes/content/CssContentTest.php
tests/phpunit/includes/content/JavaScriptContentHandlerTest.php
tests/phpunit/includes/content/JavaScriptContentTest.php

index b4f5196..a09cd15 100644 (file)
@@ -104,7 +104,7 @@ class CssContent extends TextContent {
                        // Extract the title from the url
                        preg_match( '/title=(.*?)&action=raw/', $text, $matches );
                        if ( isset( $matches[1] ) ) {
-                               $title = Title::newFromText( $matches[1] );
+                               $title = Title::newFromText( urldecode( $matches[1] ) );
                                if ( $title ) {
                                        // Have a title, check that the current content equals what
                                        // the redirect content should be
index 4bde738..69ed8d4 100644 (file)
@@ -106,7 +106,7 @@ class JavaScriptContent extends TextContent {
                        // Extract the title from the url
                        preg_match( '/title=(.*?)\\\\u0026action=raw/', $text, $matches );
                        if ( isset( $matches[1] ) ) {
-                               $title = Title::newFromText( $matches[1] );
+                               $title = Title::newFromText( urldecode( $matches[1] ) );
                                if ( $title ) {
                                        // Have a title, check that the current content equals what
                                        // the redirect content should be
index 7ca1afc..66adf73 100644 (file)
@@ -35,6 +35,10 @@ class CssContentHandlerTest extends MediaWikiLangTestCase {
                                'Gadget:FooBaz.css',
                                "/* #REDIRECT */@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);"
                        ],
+                       [
+                               'User:😂/unicode.css',
+                               '/* #REDIRECT */@import url(//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.css&action=raw&ctype=text/css);'
+                       ],
                ];
                // phpcs:enable
        }
index f5cc05e..1b5b976 100644 (file)
@@ -106,6 +106,10 @@ class CssContentTest extends JavaScriptContentTest {
                        [ 'MediaWiki:MonoBook.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=MediaWiki:MonoBook.css&action=raw&ctype=text/css);" ],
                        [ 'User:FooBar/common.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=User:FooBar/common.css&action=raw&ctype=text/css);" ],
                        [ 'Gadget:FooBaz.css', "/* #REDIRECT */@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
+                       [
+                               'User:😂/unicode.css',
+                               '/* #REDIRECT */@import url(//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.css&action=raw&ctype=text/css);'
+                       ],
                        # No #REDIRECT comment
                        [ null, "@import url(//example.org/w/index.php?title=Gadget:FooBaz.css&action=raw&ctype=text/css);" ],
                        # Wrong domain
index b5e3ab4..6a22fa0 100644 (file)
@@ -35,6 +35,10 @@ class JavaScriptContentHandlerTest extends MediaWikiLangTestCase {
                                'Gadget:FooBaz.js',
                                '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js\u0026action=raw\u0026ctype=text/javascript");'
                        ],
+                       [
+                               'User:😂/unicode.js',
+                               '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.js\u0026action=raw\u0026ctype=text/javascript");'
+                       ],
                ];
                // phpcs:enable
        }
index 9506c36..2c61b7d 100644 (file)
@@ -313,6 +313,11 @@ class JavaScriptContentTest extends TextContentTest {
                                'Gadget:FooBaz.js',
                                '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js\u0026action=raw\u0026ctype=text/javascript");'
                        ],
+                       // Unicode
+                       [
+                               'User:😂/unicode.js',
+                               '/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.js\u0026action=raw\u0026ctype=text/javascript");'
+                       ],
                        // No #REDIRECT comment
                        [
                                null,