From: Brion Vibber Date: Tue, 23 Aug 2011 20:17:49 +0000 (+0000) Subject: * (bug 30441) getParamValue must understand "+" encoding of space X-Git-Tag: 1.31.0-rc.0~28114 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=d2a1d2dba21a4cdad7a906f4d6e03e5ea0d9d0b5;p=lhc%2Fweb%2Fwiklou.git * (bug 30441) getParamValue must understand "+" encoding of space $.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. --- diff --git a/resources/mediawiki/mediawiki.util.js b/resources/mediawiki/mediawiki.util.js index d95cb8ef50..529d7c9870 100644 --- a/resources/mediawiki/mediawiki.util.js +++ b/resources/mediawiki/mediawiki.util.js @@ -226,7 +226,9 @@ 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; }, diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index d88b2733d0..ee16fe79f8 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -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() {