Revert "Do not encode "'" as %27 (redirect loop in Opera 12)"
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 10 Sep 2015 15:23:07 +0000 (15:23 +0000)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 10 Sep 2015 15:23:25 +0000 (15:23 +0000)
This seems to cause redirect loops in current Firefox instead.

This reverts commit a89a21990e9d696487c4da72f88f765e2b4b1c34.

Bug: T106793
Change-Id: I18fac8ab0f94e2df8476131b132c9866902a02c4

includes/GlobalFunctions.php
includes/Linker.php
resources/src/mediawiki/mediawiki.util.js
tests/parser/parserTests.txt
tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php
tests/phpunit/includes/LinkerTest.php
tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js

index 68e1635..b853d07 100644 (file)
@@ -404,15 +404,14 @@ function wfRandomString( $length = 32 ) {
  * RFC 1738 says ~ is unsafe, however RFC 3986 considers it an unreserved
  * character which should not be encoded. More importantly, google chrome
  * always converts %7E back to ~, and converting it in this function can
- * cause a redirect loop (T105265). Similarly, encoding ' causes a
- * redirect loop on Opera 12 (T106793).
+ * cause a redirect loop (T105265).
  *
  * But + is not safe because it's used to indicate a space; &= are only safe in
- * paths and not in queries (and we don't distinguish here);
- * and urlencode() doesn't touch -_. to begin with.  Plus, although /
+ * paths and not in queries (and we don't distinguish here); ' seems kind of
+ * scary; and urlencode() doesn't touch -_. to begin with.  Plus, although /
  * is reserved, we don't care.  So the list we unescape is:
  *
- * ;:@$!*'(),/~
+ * ;:@$!*(),/~
  *
  * However, IIS7 redirects fail when the url contains a colon (Bug 22709),
  * so no fancy : for IIS7.
@@ -431,7 +430,7 @@ function wfUrlencode( $s ) {
        }
 
        if ( is_null( $needle ) ) {
-               $needle = array( '%3B', '%40', '%24', '%21', '%2A', '%27', '%28', '%29', '%2C', '%2F', '%7E' );
+               $needle = array( '%3B', '%40', '%24', '%21', '%2A', '%28', '%29', '%2C', '%2F', '%7E' );
                if ( !isset( $_SERVER['SERVER_SOFTWARE'] ) ||
                        ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7' ) === false )
                ) {
@@ -442,7 +441,7 @@ function wfUrlencode( $s ) {
        $s = urlencode( $s );
        $s = str_ireplace(
                $needle,
-               array( ';', '@', '$', '!', '*', '\'', '(', ')', ',', '/', '~', ':' ),
+               array( ';', '@', '$', '!', '*', '(', ')', ',', '/', '~', ':' ),
                $s
        );
 
index 4d3f3ce..d6a4056 100644 (file)
@@ -939,10 +939,7 @@ class Linker {
 
                        $href = self::getUploadUrl( $title, $query );
 
-                       // @todo FIXME: If we don't to escape apostrophes (single quotes) here (using ENT_QUOTES),
-                       // then double apostrophes will be parsed as italics somewhere later in the parser,
-                       // and break everything horribly
-                       return '<a href="' . htmlspecialchars( $href, ENT_QUOTES ) . '" class="new" title="' .
+                       return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
                                htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
                                $encLabel . '</a>';
                }
index 1d11d8c..2a3542c 100644 (file)
@@ -78,7 +78,6 @@
                                .replace( /%24/g, '$' )
                                .replace( /%21/g, '!' )
                                .replace( /%2A/g, '*' )
-                               .replace( /%27/g, '\'' )
                                .replace( /%28/g, '(' )
                                .replace( /%29/g, ')' )
                                .replace( /%2C/g, ',' )
index 9cada85..aa8c9c8 100644 (file)
@@ -5711,7 +5711,7 @@ Plain ''italic'''s plain
 ###
 ### Tables
 ###
-### some content taken from http://meta.wikimedia.org/wiki/MediaWiki_User's_Guide:_Using_tables
+### some content taken from http://meta.wikimedia.org/wiki/MediaWiki_User%27s_Guide:_Using_tables
 ###
 
 # This should not produce <table></table> as <table><tr><td></td></tr></table>
@@ -7368,7 +7368,7 @@ Link containing double-single-quotes '' (bug 4598)
 !! wikitext
 [[Lista d''e paise d''o munno]]
 !! html/php
-<p><a href="/index.php?title=Lista_d''e_paise_d''o_munno&amp;action=edit&amp;redlink=1" class="new" title="Lista d''e paise d''o munno (page does not exist)">Lista d''e paise d''o munno</a>
+<p><a href="/index.php?title=Lista_d%27%27e_paise_d%27%27o_munno&amp;action=edit&amp;redlink=1" class="new" title="Lista d''e paise d''o munno (page does not exist)">Lista d''e paise d''o munno</a>
 </p>
 !! html/parsoid
 <p><a rel="mw:WikiLink" href="./Lista_d''e_paise_d''o_munno" title="Lista d''e paise d''o munno">Lista d''e paise d''o munno</a></p>
@@ -7405,10 +7405,10 @@ Link with double quotes in title part (literal) and alternate part (interpreted)
 
 [[''Pentecoste''|''Pentecoste'']]
 !! html/php
-<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Denys_Savchenko_&#39;&#39;Pentecoste&#39;&#39;.jpg" class="new" title="File:Denys Savchenko &#39;&#39;Pentecoste&#39;&#39;.jpg">File:Denys Savchenko <i>Pentecoste</i>.jpg</a>
-</p><p><a href="/index.php?title=''Pentecoste''&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">''Pentecoste''</a>
-</p><p><a href="/index.php?title=''Pentecoste''&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">Pentecoste</a>
-</p><p><a href="/index.php?title=''Pentecoste''&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)"><i>Pentecoste</i></a>
+<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Denys_Savchenko_%27%27Pentecoste%27%27.jpg" class="new" title="File:Denys Savchenko &#39;&#39;Pentecoste&#39;&#39;.jpg">File:Denys Savchenko <i>Pentecoste</i>.jpg</a>
+</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">''Pentecoste''</a>
+</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">Pentecoste</a>
+</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)"><i>Pentecoste</i></a>
 </p>
 !! html/parsoid
 <p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}]}'><a href="./File:Denys_Savchenko_''Pentecoste''.jpg"><img resource="./File:Denys_Savchenko_''Pentecoste''.jpg" src="./Special:FilePath/Denys_Savchenko_''Pentecoste''.jpg" height="220" width="220"/></a></span></p>
@@ -14033,7 +14033,7 @@ Link to category
 !! wikitext
 [[:Category:MediaWiki User's Guide]]
 !! html
-<p><a href="/wiki/Category:MediaWiki_User's_Guide" title="Category:MediaWiki User's Guide">Category:MediaWiki User's Guide</a>
+<p><a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">Category:MediaWiki User's Guide</a>
 </p>
 !! end
 
@@ -14044,7 +14044,7 @@ cat
 !! wikitext
 [[Category:MediaWiki User's Guide]]
 !! html
-<a href="/wiki/Category:MediaWiki_User's_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
+<a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
 !! end
 
 !! test
@@ -14063,7 +14063,7 @@ cat
 !! wikitext
 [[Category:MediaWiki User's Guide|Foo]]
 !! html
-<a href="/wiki/Category:MediaWiki_User's_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
+<a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
 !! end
 
 !! test
@@ -14073,7 +14073,7 @@ cat
 !! wikitext
 [[Category:MediaWiki User's Guide|MediaWiki User's Guide]]
 !! html
-<a href="/wiki/Category:MediaWiki_User's_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
+<a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
 !! end
 
 !! test
@@ -19025,7 +19025,7 @@ language=sr cat
 !! wikitext
 [[Category:МедиаWики Усер'с Гуиде]]
 !! html
-<a href="/wiki/%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%98%D0%B0:MediaWiki_User's_Guide" title="Категорија:MediaWiki User's Guide">MediaWiki User's Guide</a>
+<a href="/wiki/%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%98%D0%B0:MediaWiki_User%27s_Guide" title="Категорија:MediaWiki User's Guide">MediaWiki User's Guide</a>
 !! end
 
 
@@ -20981,7 +20981,7 @@ File:foobar.jpg|caption|alt=galleryalt|link=" onclick="alert('malicious javascri
 !! html
 <ul class="gallery mw-gallery-traditional">
                <li class="gallerybox" style="width: 155px"><div style="width: 155px">
-                       <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/%22_onclick%3D%22alert(&#39;malicious_javascript_code!&#39;);"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
+                       <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/%22_onclick%3D%22alert(%27malicious_javascript_code!%27);"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
                        <div class="gallerytext">
 <p>caption
 </p>
index 07dcabc..d4df7b0 100644 (file)
@@ -105,8 +105,8 @@ class WfUrlencodeTest extends MediaWikiTestCase {
 
                        // remaining chars do not need encoding
                        array(
-                               ';@$-_.!*\'',
-                               ';@$-_.!*\'',
+                               ';@$-_.!*',
+                               ';@$-_.!*',
                        ),
 
                        ### Other tests
@@ -118,6 +118,9 @@ class WfUrlencodeTest extends MediaWikiTestCase {
                        // Other 'funnies' chars
                        array( '[]', '%5B%5D' ),
                        array( '<>', '%3C%3E' ),
+
+                       // Apostrophe is encoded
+                       array( '\'', '%27' ),
                );
        }
 }
index 1122ddd..823c933 100644 (file)
@@ -232,7 +232,7 @@ class LinkerTest extends MediaWikiLangTestCase {
                                null,
                        ),
                        array(
-                               '<a class="external" rel="nofollow" href="//en.example.org/w/Foo\'bar">Foo\'bar</a>',
+                               '<a class="external" rel="nofollow" href="//en.example.org/w/Foo%27bar">Foo\'bar</a>',
                                "[[Foo'bar]]",
                                'enwiki',
                        ),
index 0cd8ac0..a105022 100644 (file)
                        'Bar in anchor'
                );
 
-               expectedSpecialCharacters = '<a title="&quot;Who&quot; wants to be a millionaire &amp; live on &#039;Exotic Island&#039;?" href="/wiki/%22Who%22_wants_to_be_a_millionaire_%26_live_on_&#039;Exotic_Island&#039;%3F">&quot;Who&quot; wants to be a millionaire &amp; live on &#039;Exotic Island&#039;?</a>';
+               expectedSpecialCharacters = '<a title="&quot;Who&quot; wants to be a millionaire &amp; live on &#039;Exotic Island&#039;?" href="/wiki/%22Who%22_wants_to_be_a_millionaire_%26_live_on_%27Exotic_Island%27%3F">&quot;Who&quot; wants to be a millionaire &amp; live on &#039;Exotic Island&#039;?</a>';
 
                mw.messages.set( 'special-characters', '[[' + specialCharactersPageName + ']]' );
                assert.htmlEqual(
index d70d1d0..450f0f5 100644 (file)
@@ -92,7 +92,7 @@
                assert.equal( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' );
        } );
 
-       QUnit.test( 'wikiUrlencode', 10, function ( assert ) {
+       QUnit.test( 'wikiUrlencode', 11, function ( assert ) {
                assert.equal( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' );
                // See also wfUrlencodeTest.php#provideURLS
                $.each( {
                        '&': '%26',
                        '=': '%3D',
                        ':': ':',
-                       ';@$-_.!*\'': ';@$-_.!*\'',
+                       ';@$-_.!*': ';@$-_.!*',
                        '/': '/',
                        '~': '~',
                        '[]': '%5B%5D',
-                       '<>': '%3C%3E'
+                       '<>': '%3C%3E',
+                       '\'': '%27'
                }, function ( input, output ) {
                        assert.equal( mw.util.wikiUrlencode( input ), output );
                } );