diff --git a/CHANGELOG b/CHANGELOG index 75dd48f..daefe8b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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] diff --git a/src/hash.js b/src/hash.js index b2d4872..125a96b 100644 --- a/src/hash.js +++ b/src/hash.js @@ -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('&'); }, diff --git a/test/unit/hash.html b/test/unit/hash.html index d52ea9f..08ee58b 100644 --- a/test/unit/hash.html +++ b/test/unit/hash.html @@ -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);