This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,9 @@ function $HttpParamSerializerJQLikeProvider() {
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
+ parts . push ( encodeUriQuery ( prefix ) + '=' + encodeUriQuery ( toSerialize . toJSON ( ) ) ) ;
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,20 @@ 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 honor toJSON function' , function ( ) {
2053
+ expect ( jqrSer ( {
2054
+ foo : {
2055
+ a : 'b' ,
2056
+ toJSON : function ( ) {
2057
+ return 'baz' ;
2058
+ }
2059
+ } ,
2060
+ bar : {
2061
+ c : 'd'
2062
+ }
2063
+ } ) ) . toEqual ( 'bar%5Bc%5D=d&foo=baz' ) ;
2064
+ } ) ;
2065
+
2052
2066
} ) ;
2053
2067
2054
2068
describe ( 'default array serialization' , function ( ) {
You can’t perform that action at this time.
0 commit comments