This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +35
-2
lines changed
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -110,12 +110,14 @@ function $HttpParamSerializerJQLikeProvider() {
110
110
return parts . join ( '&' ) ;
111
111
112
112
function serialize ( toSerialize , prefix , topLevel ) {
113
- if ( toSerialize === null || isUndefined ( toSerialize ) ) return ;
113
+ if ( toSerialize === null || isUndefined ( toSerialize ) || isFunction ( toSerialize ) ) return ;
114
114
if ( isArray ( toSerialize ) ) {
115
115
forEach ( toSerialize , function ( value , index ) {
116
116
serialize ( value , prefix + '[' + ( isObject ( value ) ? index : '' ) + ']' ) ;
117
117
} ) ;
118
- } else if ( isObject ( toSerialize ) && ! isDate ( toSerialize ) ) {
118
+ } else if ( isFunction ( toSerialize . toJSON ) ) {
119
+ serialize ( toSerialize . toJSON ( ) , prefix , topLevel ) ;
120
+ } else if ( isObject ( toSerialize ) ) {
119
121
forEachSorted ( toSerialize , function ( value , key ) {
120
122
serialize ( value , prefix +
121
123
( topLevel ? '' : '[' ) +
Original file line number Diff line number Diff line change @@ -2274,6 +2274,37 @@ describe('$http param serializers', function() {
2274
2274
expect ( jqrSer ( { someDate : new Date ( '2014-07-15T17:30:00.000Z' ) } ) ) . toEqual ( 'someDate=2014-07-15T17:30:00.000Z' ) ;
2275
2275
} ) ;
2276
2276
2277
+ it ( 'should ignore functions' , function ( ) {
2278
+ expect ( jqrSer ( {
2279
+ foo : {
2280
+ a : 'b' ,
2281
+ c : function ( ) {
2282
+ return 'd' ;
2283
+ }
2284
+ }
2285
+ } ) ) . toEqual ( 'foo%5Ba%5D=b' ) ;
2286
+ } ) ;
2287
+
2288
+ it ( 'should honor toJSON function' , function ( ) {
2289
+ expect ( jqrSer ( {
2290
+ foo : {
2291
+ a : 'b' ,
2292
+ toJSON : function ( ) {
2293
+ return {
2294
+ e : 'f' ,
2295
+ g : 'h'
2296
+ } ;
2297
+ }
2298
+ } ,
2299
+ bar : {
2300
+ c : 'd' ,
2301
+ toJSON : function ( ) {
2302
+ return 'baz' ;
2303
+ }
2304
+ }
2305
+ } ) ) . toEqual ( 'bar=baz&foo%5Be%5D=f&foo%5Bg%5D=h' ) ;
2306
+ } ) ;
2307
+
2277
2308
} ) ;
2278
2309
2279
2310
describe ( 'default array serialization' , function ( ) {
You can’t perform that action at this time.
0 commit comments