mediawiki.Uri: Don't raw encode the 'title' query parameter.
authorTimo Tijhof <ttijhof@wikimedia.org>
Sun, 2 Dec 2012 04:11:06 +0000 (05:11 +0100)
committerTimo Tijhof <ttijhof@wikimedia.org>
Sun, 2 Dec 2012 04:11:06 +0000 (05:11 +0100)
Previously:

Input:
 http://alpha.wiki.krinkle.dev/w/index.php?title=Sandbox/2&oldid=611&veaction=edit
Action:
 remove query.veaction
Output:
 http://alpha.wiki.krinkle.dev/w/index.php?title=Sandbox%2F2&oldid=611

Now the title parameter stays the same.

Change-Id: Ieb9eee450ea8ae3cc97bab12de935c6e7b103842

resources/mediawiki/mediawiki.Uri.js
tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js

index f85dec8..2cb4c3a 100644 (file)
                                        var k = Uri.encode( key ),
                                                vals = $.isArray( val ) ? val : [ val ];
                                        $.each( vals, function ( i, v ) {
-                                               args.push( k + ( v === null ? '' : '=' + Uri.encode( v ) ) );
+                                               if ( v === null ) {
+                                                       args.push( k );
+                                               } else if ( k === 'title' ) {
+                                                       args.push( k + '=' + mw.util.wikiUrlencode( v ) );
+                                               } else {
+                                                       args.push( k + '=' + Uri.encode( v ) );
+                                               }
                                        } );
                                } );
                                return args.join( '&' );
index f9927f0..aba6a0c 100644 (file)
@@ -88,7 +88,7 @@
                );
        } );
 
-       QUnit.test( 'Parse a uri with simple querystring', 1, function ( assert ) {
+       QUnit.test( '.getQueryString()', 2, function ( assert ) {
                var uri = new mw.Uri( 'http://www.google.com/?q=uri' );
 
                assert.deepEqual(
                        },
                        'basic object properties'
                );
+
+               uri = new mw.Uri( 'https://example.org/mw/index.php?title=Sandbox/7&other=Sandbox/7&foo' );
+               assert.equal(
+                       uri.getQueryString(),
+                       'title=Sandbox/7&other=Sandbox%2F7&foo',
+                       'title parameter is escaped the wiki-way'
+               );
+
        } );
 
        QUnit.test( 'Handle multiple query parameter (overrideKeys on)', 5, function ( assert ) {