* (bug 30441) getParamValue must understand "+" encoding of space
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 23 Aug 2011 20:17:49 +0000 (20:17 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 23 Aug 2011 20:17:49 +0000 (20:17 +0000)
$.param() produces query string form encoding using the traditional '+' encoding for space; mediawiki.util.getParamValue() was using only decodeURIComponent() to do unescaping, which is not required by spec to handle '+'. Explicitly replacing '+' with '%20' before the decode nicely resolves this.

Added a test case to qunit tests for mediawiki.util module.

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

index d95cb8e..529d7c9 100644 (file)
                        var re = new RegExp( '^[^#]*[&?]' + $.escapeRE( param ) + '=([^&#]*)' );
                        var m = re.exec( url );
                        if ( m && m.length > 1 ) {
-                               return decodeURIComponent( m[1] );
+                               // Beware that decodeURIComponent is not required to understand '+'
+                               // by spec, as encodeURIComponent does not produce it.
+                               return decodeURIComponent( m[1].replace( '+', '%20' ) );
                        }
                        return null;
                },
index d88b273..ee16fe7 100644 (file)
@@ -107,7 +107,7 @@ test( 'toggleToc', function() {
 });
 
 test( 'getParamValue', function() {
-       expect(3);
+       expect(4);
 
        var     url1 = 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad';
 
@@ -116,6 +116,9 @@ test( 'getParamValue', function() {
 
        var url2 = 'http://mediawiki.org/#&foo=bad';
        strictEqual( mw.util.getParamValue( 'foo', url2 ), null, 'Ignore hash if param is not in querystring but in hash (bug 27427)' );
+
+       var url3 = 'example.com?' + $.param({ 'TEST': 'a b+c' });
+       strictEqual( mw.util.getParamValue( 'TEST', url3 ), 'a b+c', 'Bug 30441: getParamValue must understand "+" encoding of space' );
 });
 
 test( 'tooltipAccessKey', function() {