Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 919ea72

Browse files
committed
feat($httpParamSerializerJQLike): honor object.toJSON function if present.
1 parent 9ea52d8 commit 919ea72

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/ng/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function $HttpParamSerializerJQLikeProvider() {
111111
forEach(toSerialize, function(value) {
112112
serialize(value, prefix + '[]');
113113
});
114-
} else if (isObject(toSerialize) && !isDate(toSerialize)) {
114+
} else if (isObject(toSerialize) && !isFunction(toSerialize.toJSON)) {
115115
forEachSorted(toSerialize, function(value, key) {
116116
serialize(value, prefix +
117117
(topLevel ? '' : '[') +

test/ng/httpSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,20 @@ describe('$http param serializers', function() {
19991999
expect(jqrSer({someDate: new Date('2014-07-15T17:30:00.000Z')})).toEqual('someDate=2014-07-15T17:30:00.000Z');
20002000
});
20012001

2002+
it('should honor toJSON function', function() {
2003+
expect(jqrSer({
2004+
foo: {
2005+
a: 'b',
2006+
toJSON: function () {
2007+
return 'baz';
2008+
}
2009+
},
2010+
bar: {
2011+
c: 'd'
2012+
}
2013+
})).toEqual('bar%5Bc%5D=d&foo=%22baz%22');
2014+
});
2015+
20022016
});
20032017

20042018
describe('default array serialization', function() {

0 commit comments

Comments
 (0)