Last modified: 2011-08-23 20:19:23 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T32441, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 30441 - Encoding problem with mw.util.getParamValue() and $.param
Encoding problem with mw.util.getParamValue() and $.param
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
unspecified
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
: need-unittest
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-08-18 13:27 UTC by Helder
Modified: 2011-08-23 20:19 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Helder 2011-08-18 13:27:45 UTC
If we try to use
----
mw.util.getParamValue( 'TEST', 'example.com?' + $.param({ 'TEST': 'a b+c' }) )
----

the result will be "a+b+c", which is wrong and breaks some scripts. Compare with
----
decodeURIComponent(encodeURIComponent('a b+c'))
----
which results in "a b+c", as expected.


Is it possible to fix mw.util.getParamValue so that we can get the original parameter value?
Comment 1 Helder 2011-08-18 13:56:07 UTC
For an example of an script which was affected by this issue, and a possible workaround, see:
https://secure.wikimedia.org/wikipedia/pt/w/index.php?title=MediaWiki:Gadget-fastbuttons.js&oldid=26543813&diff=26548085&uselang=en


The problem seems related to/caused by this
http://bugs.jquery.com/ticket/3400
Comment 2 Helder 2011-08-18 14:26:10 UTC
(In reply to comment #1)
> The problem seems related to/caused by this
> http://bugs.jquery.com/ticket/3400

Specifically, this line:
https://github.com/jquery/jquery/blob/master/src/ajax.js#L794

so, would it be possible to remove the .replace( r20, "+" ); from $.param(), or will we need to just avoid using this jQuery function (or recreating it on each WMF wiki when needed)?

CCing Michael Dale since he may know if this problem also happens with the mw.Uri suggested on bug 27730 comment 5.
Comment 3 Brion Vibber 2011-08-23 20:12:07 UTC
This should be fixable simply by throwing a .replace('+', '%20') into getParamValue() in mediawiki.util.js before the decodeURIComponent.


Per spec, encodeURIComponent/decodeURIComponent work with the %20 form -- which is what's always used in URI path components -- so if you want to handle '+'s (traditionally used in query string form encoding) you have to do that as an additional step.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent

http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
Comment 4 Brion Vibber 2011-08-23 20:19:23 UTC
Fixed on trunk in r95332. Probably needs merge back to 1.18, 1.17.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links