Skip to content

Commit 771dcd2

Browse files
Merge pull request #12 from sabberworm/bugfix/object-with-null-prototype
Bugfix for objects with null prototype
2 parents 6bd3039 + c37b219 commit 771dcd2

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

esm/jquery-param.es.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var param = function (a) {
2525
obj[i]
2626
);
2727
}
28-
} else if (String(obj) === '[object Object]') {
28+
} else if (Object.prototype.toString.call(obj) === '[object Object]') {
2929
for (key in obj) {
3030
buildParams(prefix + '[' + key + ']', obj[key]);
3131
}

esm/jquery-param.es.min.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
22
jquery-param (c) KNOWLEDGECODE | MIT
33
*/
4-
export default function(h){function d(c,a){var e;if(c)if(Array.isArray(a)){var b=0;for(e=a.length;b<e;b++)d(c+"["+("object"===typeof a[b]&&a[b]?b:"")+"]",a[b])}else if("[object Object]"===String(a))for(b in a)d(c+"["+b+"]",a[b]);else g(c,a);else if(Array.isArray(a))for(b=0,e=a.length;b<e;b++)g(a[b].name,a[b].value);else for(b in a)d(b,a[b]);return f}function g(c,a){a="function"===typeof a?a():a;a=null===a?"":void 0===a?"":a;f[f.length]=encodeURIComponent(c)+"="+encodeURIComponent(a)}var f=
5-
[];return d("",h).join("&")}
4+
export default function(h){function d(c,a){var e;if(c)if(Array.isArray(a)){var b=0;for(e=a.length;b<e;b++)d(c+"["+("object"===typeof a[b]&&a[b]?b:"")+"]",a[b])}else if("[object Object]"===Object.prototype.toString.call(a))for(b in a)d(c+"["+b+"]",a[b]);else g(c,a);else if(Array.isArray(a))for(b=0,e=a.length;b<e;b++)g(a[b].name,a[b].value);else for(b in a)d(b,a[b]);return f}function g(c,a){a="function"===typeof a?a():a;a=null===a?"":void 0===a?"":a;f[f.length]=encodeURIComponent(c)+"="+
5+
encodeURIComponent(a)}var f=[];return d("",h).join("&")}

jquery-param.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
obj[i]
3232
);
3333
}
34-
} else if (String(obj) === '[object Object]') {
34+
} else if (Object.prototype.toString.call(obj) === '[object Object]') {
3535
for (key in obj) {
3636
buildParams(prefix + '[' + key + ']', obj[key]);
3737
}

jquery-param.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var param = function (a) {
2525
obj[i]
2626
);
2727
}
28-
} else if (String(obj) === '[object Object]') {
28+
} else if (Object.prototype.toString.call(obj) === '[object Object]') {
2929
for (key in obj) {
3030
buildParams(prefix + '[' + key + ']', obj[key]);
3131
}

test/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,13 @@
852852
var obj = NaN;
853853
test(done, obj);
854854
});
855+
856+
it('null Prototype', function (done) {
857+
var obj = Object.create(null);
858+
obj.test = Object.create(null);
859+
obj.test.test = 1;
860+
test(done, obj);
861+
});
855862
});
856863

857864
}(this));

0 commit comments

Comments
 (0)