prototype: Prevent Hash#toQueryString from serializing objets.

This commit is contained in:
Tobie Langel 2008-03-19 13:01:47 +00:00
parent 32b1b6b7cd
commit 598387f137
3 changed files with 7 additions and 4 deletions

View File

@ -1,3 +1,5 @@
* Prevent Hash#toQueryString from serializing objets. [kangax, Tobie Langel]
* Fix Event#pointer in IE standard mode. Closes #9920. [kangax, Tobie Langel]
* Instanciate Test.Unit.Logger on window load. [Tobie Langel]

View File

@ -68,14 +68,14 @@ var Hash = Class.create(Enumerable, (function() {
},
toQueryString: function() {
return this.map(function(pair) {
return this.inject([], function(results, pair) {
var key = encodeURIComponent(pair.key), values = pair.value;
if (values && typeof values == 'object') {
if (Object.isArray(values))
return values.map(toQueryPair.curry(key)).join('&');
}
return toQueryPair(key, values);
return results.concat(values.map(toQueryPair.curry(key)));
} else results.push(toQueryPair(key, values));
return results;
}).join('&');
},

View File

@ -172,6 +172,7 @@
this.assertEqual("color=r&color=&color=g&color&color=0", $H(Fixtures.multiple_nil).toQueryString());
this.assertEqual("color=&color", $H(Fixtures.multiple_all_nil).toQueryString());
this.assertEqual("", $H(Fixtures.multiple_empty).toQueryString());
this.assertEqual("", $H({foo: {}, bar: {}}).toQueryString());
this.assertEqual("stuff%5B%5D=%24&stuff%5B%5D=a&stuff%5B%5D=%3B", $H(Fixtures.multiple_special).toQueryString());
this.assertHashEqual(Fixtures.multiple_special, $H(Fixtures.multiple_special).toQueryString().toQueryParams());
this.assertIdentical(Object.toQueryString, Hash.toQueryString);