Last modified: 2012-07-19 21:15:51 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 T29942, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 27942 - make mw.Uri.js handle query arguments that appear multiple times
make mw.Uri.js handle query arguments that appear multiple times
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
1.20.x
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-08 18:13 UTC by Neil Kandalgaonkar
Modified: 2012-07-19 21:15 UTC (History)
4 users (show)

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


Attachments

Description Neil Kandalgaonkar 2011-03-08 18:13:50 UTC
mw.Uri.js models the query as an object of simple key-values. This is not strictly correct as you can have

  key=value&key=anotherValue

If it is to replace certain functions in mw.util.js, such as getParamValue it needs to handle that case.
Comment 1 Krinkle 2011-03-08 19:35:37 UTC
More precise, it needs to return the last one (since that one overwrites the earlier one).
Most regexes around (haven't looked into mw.Uri.js), stop at the first match.
Comment 2 Neil Kandalgaonkar 2011-03-08 19:55:55 UTC
Krinkle: no, that's not correct -- in the HTTP standard it is permissible to have multiple values for a key in the query string, and they all count. 

In HTML, this can result from submitting a form with a SELECT with the MULTIPLE attribute on, so you can select multiple values.

Or are you saying that something in MediaWiki parses URLs that way? If so it's wrong.
Comment 3 Bugmeister Bot 2011-08-19 19:12:38 UTC
Unassigning default assignments. http://article.gmane.org/gmane.science.linguistics.wikipedia.technical/54734
Comment 4 Brion Vibber 2011-09-14 23:34:32 UTC
It is permissible to have an argument appear multiple times, however *unless its name ends in "[]" PHP will just overwrite all the earlier ones with the later ones when it interprets input.

Query string / POST elements whose names end in '[]' or '[<index>]' produce array elements, which may have either numeric or string keys.

If you have [] on the end of the name, then it saves the one-or-more elements into an array with the name without the [].

Within MediaWiki we fairly consistently use the associative-array model here, with sub-arrays for multiple items getting the [] added on the generated URL:

> parse_str('a[]=b&a[]=c', $foo); var_export($foo);
array (
  'a' => 
  array (
    0 => 'b',
    1 => 'c',
  ),
)
> parse_str('a[xx]=b&a[yy]=c', $foo); var_export($foo);
array (
  'a' => 
  array (
    'xx' => 'b',
    'yy' => 'c',
  ),
)

> return wfArrayToCGI(array('a' => array('b', 'c')));
a%5B0%5D=b&a%5B1%5D=c

> return wfArrayToCGI(array('a' => array('xx' => 'b', 'yy' => 'c')));
a%5Bxx%5D=b&a%5Byy%5D=c

mw.Uri should probably model these similarly... $.param already seems to do this for serializing parameters into query strings:

>>> $.param({a: "b"});
"a=b"

>>> $.param({a: ["b", "c"]});
"a%5B%5D=b&a%5B%5D=c"

>>> $.param({a: {xx: "b", yy: "c"}});
"a%5Bxx%5D=b&a%5Byy%5D=c"
Comment 5 Brion Vibber 2011-09-14 23:38:37 UTC
Moving bug out of UploadWizard to core, as this JS module has migrated into core.
Comment 6 Neil Kandalgaonkar 2011-09-15 00:01:01 UTC
This bug is resolved, just was lazy about marking it. The migration to core has obscured history a bit but see lines 169-176, or look at r83691. As for compatibility with what PHP wants to see that seems to be a matter of the application doing the right thing when constructing the URI. It is not a given that all URIs constructed with this module are supposed to be consumed by MediaWiki or PHP.
Comment 7 Neil Kandalgaonkar 2011-09-15 01:23:40 UTC
Okay, actually, maybe it would be a good idea to handle all that with $.param(), and there is a decently documented function in jQuery BBQ which unserializes URLs much like $.param(), even for complex values like ?foo[a][b]=var .

However, now I remember why I didn't use $.param(); we like to escape things differently (for whatever reason we always escape parentheses, for example).

Looking into whether I can fiddle with jQuery's escaping routines there.
Comment 8 Mark Holmquist 2012-07-19 21:15:51 UTC
This appears to be very resolved. mw.Uri now handles multiple arguments as an array, properly. Also, while I cannot find the relevant code, there is a commit message that says something about more-PHP-like array handling.

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


Navigation
Links