This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -417,6 +417,11 @@ function isScope(obj) {
417417}
418418
419419
420+ function isFile ( obj ) {
421+ return toString . apply ( obj ) === '[object File]' ;
422+ }
423+
424+
420425function isBoolean ( value ) { return typeof value == $boolean ; }
421426function isTextNode ( node ) { return nodeName_ ( node ) == '#text' ; }
422427
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ function $HttpProvider() {
102102
103103 // transform outgoing request data
104104 transformRequest : function ( d ) {
105- return isObject ( d ) ? toJson ( d ) : d ;
105+ return isObject ( d ) && ! isFile ( d ) ? toJson ( d ) : d ;
106106 } ,
107107
108108 // default headers
Original file line number Diff line number Diff line change @@ -564,6 +564,25 @@ describe('$http', function() {
564564 $httpBackend . expect ( 'POST' , '/url' , 'string-data' ) . respond ( '' ) ;
565565 $http ( { method : 'POST' , url : '/url' , data : 'string-data' } ) ;
566566 } ) ;
567+
568+
569+ it ( 'should ignore File objects' , function ( ) {
570+ var file = {
571+ some : true ,
572+ // $httpBackend compares toJson values by default,
573+ // we need to be sure it's not serialized into json string
574+ test : function ( actualValue ) {
575+ return this === actualValue ;
576+ }
577+ } ;
578+
579+ // I'm really sorry for doing this :-D
580+ // Unfortunatelly I don't know how to trick toString.apply(obj) comparison
581+ spyOn ( window , 'isFile' ) . andReturn ( true ) ;
582+
583+ $httpBackend . expect ( 'POST' , '/some' , file ) . respond ( '' ) ;
584+ $http ( { method : 'POST' , url : '/some' , data : file } ) ;
585+ } ) ;
567586 } ) ;
568587
569588
You can’t perform that action at this time.
0 commit comments