This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,9 @@ function $HttpParamSerializerJQLikeProvider() {
117117 forEach ( toSerialize , function ( value , index ) {
118118 serialize ( value , prefix + '[' + ( isObject ( value ) ? index : '' ) + ']' ) ;
119119 } ) ;
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 ) ) {
121123 forEachSorted ( toSerialize , function ( value , key ) {
122124 serialize ( value , prefix +
123125 ( topLevel ? '' : '[' ) +
Original file line number Diff line number Diff line change @@ -2030,6 +2030,20 @@ describe('$http param serializers', function() {
20302030 expect ( jqrSer ( { someDate : new Date ( '2014-07-15T17:30:00.000Z' ) } ) ) . toEqual ( 'someDate=2014-07-15T17:30:00.000Z' ) ;
20312031 } ) ;
20322032
2033+ it ( 'should honor toJSON function' , function ( ) {
2034+ expect ( jqrSer ( {
2035+ foo : {
2036+ a : 'b' ,
2037+ toJSON : function ( ) {
2038+ return 'baz' ;
2039+ }
2040+ } ,
2041+ bar : {
2042+ c : 'd'
2043+ }
2044+ } ) ) . toEqual ( 'bar%5Bc%5D=d&foo=baz' ) ;
2045+ } ) ;
2046+
20332047 } ) ;
20342048
20352049 describe ( 'default array serialization' , function ( ) {
You can’t perform that action at this time.
0 commit comments