Skip to content

Commit

Permalink
Adjusted query string array representation to remove indices. (#8342)
Browse files Browse the repository at this point in the history
* Adjusted query string array representation to remove indices.

* Increased major version since the new _encodeParams() result is not backwards compatiable.
  • Loading branch information
hwillson authored and benjamn committed Feb 10, 2017
1 parent 57f3eac commit 0830967
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/url/package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
summary: "Utility code for constructing URLs",
version: "1.0.11"
version: "2.0.0"
});

Package.onUse(function(api) {
Expand Down
4 changes: 3 additions & 1 deletion packages/url/url_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ var encodeString = function (str) {
// arrays properly.
URL._encodeParams = function (params, prefix) {
var str = [];
var isParamsArray = Array.isArray(params);
for (var p in params) {
if (Object.prototype.hasOwnProperty.call(params, p)) {
var k = prefix ? prefix + '[' + p + ']' : p, v = params[p];
var k = prefix ? prefix + '[' + (isParamsArray ? '' : p) + ']' : p;
var v = params[p];
if (typeof v === 'object') {
str.push(this._encodeParams(v, k));
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/url/url_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Tinytest.add('url - serializes params to query correctly', function (test) {
hasOwnProperty: 'horrible param name',
};
var query =
'filter[type]=Foo&filter[id_eq]=15&array[0]=1&array[1]=a'
+ '&array[2]=dirty%5B%5D&hasOwnProperty=horrible+param+name';
'filter[type]=Foo&filter[id_eq]=15&array[]=1&array[]=a'
+ '&array[]=dirty%5B%5D&hasOwnProperty=horrible+param+name';
test.equal(URL._encodeParams(hash), query);
});

0 comments on commit 0830967

Please sign in to comment.