mootools / mootools-core

MooTools Core Repository
https://mootools.net
2.65k stars 507 forks source link

Fixed handle of arrays in Object.toQueryString. #2744

Open jarkt opened 8 years ago

jarkt commented 8 years ago
Object.toQueryString({
  "a": [1, 2],
  "b": {"": [3, 4], "x": "y"},
  "c": null,
  "d": "e"
})

Old result: a[0]=1&a[1]=2&b[][0]=3&b[][1]=4&b[x]=y&d=e New result: a=1&a=2&b[]=3&b[]=4&b[x]=y&d=e

SergioCrisostomo commented 8 years ago

@jarkt thank you for the fix suggestion!

There are specs failing with this code suggestion. Which means a BC (breaking change).

Which issue is this fixing? Is this related with URI issues in More?

jarkt commented 8 years ago

Yes exactly. The function shouldn’t automatically number parameters with the same name. I think the specs are wrong.

Object.toQueryString("a[]=1&a[]=2".parseQueryString())

This should return only the input string, but instead mootools adds one more dimension and returns "a[][0]=1&a[][1]=2". parseQueryString and toQueryString actually don’t work fine together.