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 @@ -2056,6 +2056,37 @@ describe('$http param serializers', function() {
2056
2056
expect ( jqrSer ( { someDate : new Date ( '2014-07-15T17:30:00.000Z' ) } ) ) . toEqual ( 'someDate=2014-07-15T17:30:00.000Z' ) ;
2057
2057
} ) ;
2058
2058
2059
+ it ( 'should ignore functions' , function ( ) {
2060
+ expect ( jqrSer ( {
2061
+ foo : {
2062
+ a : 'b' ,
2063
+ c : function ( ) {
2064
+ return 'd' ;
2065
+ }
2066
+ }
2067
+ } ) ) . toEqual ( 'foo%5Ba%5D=b' ) ;
2068
+ } ) ;
2069
+
2070
+ it ( 'should honor toJSON function' , function ( ) {
2071
+ expect ( jqrSer ( {
2072
+ foo : {
2073
+ a : 'b' ,
2074
+ toJSON : function ( ) {
2075
+ return {
2076
+ e : 'f' ,
2077
+ g : 'h'
2078
+ } ;
2079
+ }
2080
+ } ,
2081
+ bar : {
2082
+ c : 'd' ,
2083
+ toJSON : function ( ) {
2084
+ return 'baz' ;
2085
+ }
2086
+ }
2087
+ } ) ) . toEqual ( 'bar=baz&foo%5Be%5D=f&foo%5Bg%5D=h' ) ;
2088
+ } ) ;
2089
+
2059
2090
} ) ;
2060
2091
2061
2092
describe ( 'default array serialization' , function ( ) {
You can’t perform that action at this time.
0 commit comments