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 @@ -112,12 +112,14 @@ function $HttpParamSerializerJQLikeProvider() {
112
112
return parts . join ( '&' ) ;
113
113
114
114
function serialize ( toSerialize , prefix , topLevel ) {
115
- if ( toSerialize === null || isUndefined ( toSerialize ) ) return ;
115
+ if ( toSerialize === null || isUndefined ( toSerialize ) || isFunction ( toSerialize ) ) return ;
116
116
if ( isArray ( toSerialize ) ) {
117
117
forEach ( toSerialize , function ( value , index ) {
118
118
serialize ( value , prefix + '[' + ( isObject ( value ) ? index : '' ) + ']' ) ;
119
119
} ) ;
120
- } else if ( isObject ( toSerialize ) && ! isDate ( toSerialize ) ) {
120
+ } else if ( isFunction ( toSerialize . toJSON ) ) {
121
+ serialize ( toSerialize . toJSON ( ) , prefix , topLevel ) ;
122
+ } else if ( isObject ( toSerialize ) ) {
121
123
forEachSorted ( toSerialize , function ( value , key ) {
122
124
serialize ( value , prefix +
123
125
( topLevel ? '' : '[' ) +
Original file line number Diff line number Diff line change @@ -2049,6 +2049,37 @@ describe('$http param serializers', function() {
2049
2049
expect ( jqrSer ( { someDate : new Date ( '2014-07-15T17:30:00.000Z' ) } ) ) . toEqual ( 'someDate=2014-07-15T17:30:00.000Z' ) ;
2050
2050
} ) ;
2051
2051
2052
+ it ( 'should ignore functions' , function ( ) {
2053
+ expect ( jqrSer ( {
2054
+ foo : {
2055
+ a : 'b' ,
2056
+ c : function ( ) {
2057
+ return 'd' ;
2058
+ }
2059
+ }
2060
+ } ) ) . toEqual ( 'foo%5Ba%5D=b' ) ;
2061
+ } ) ;
2062
+
2063
+ it ( 'should honor toJSON function' , function ( ) {
2064
+ expect ( jqrSer ( {
2065
+ foo : {
2066
+ a : 'b' ,
2067
+ toJSON : function ( ) {
2068
+ return {
2069
+ e : 'f' ,
2070
+ g : 'h'
2071
+ } ;
2072
+ }
2073
+ } ,
2074
+ bar : {
2075
+ c : 'd' ,
2076
+ toJSON : function ( ) {
2077
+ return 'baz' ;
2078
+ }
2079
+ }
2080
+ } ) ) . toEqual ( 'bar=baz&foo%5Be%5D=f&foo%5Bg%5D=h' ) ;
2081
+ } ) ;
2082
+
2052
2083
} ) ;
2053
2084
2054
2085
describe ( 'default array serialization' , function ( ) {
You can’t perform that action at this time.
0 commit comments