$.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.
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;
},
});
test( 'getParamValue', function() {
- expect(3);
+ expect(4);
var url1 = 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad';
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() {