This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 3 files changed +25
-1
lines changed
3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -417,6 +417,11 @@ function isScope(obj) {
417
417
}
418
418
419
419
420
+ function isFile ( obj ) {
421
+ return toString . apply ( obj ) === '[object File]' ;
422
+ }
423
+
424
+
420
425
function isBoolean ( value ) { return typeof value == $boolean ; }
421
426
function isTextNode ( node ) { return nodeName_ ( node ) == '#text' ; }
422
427
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ function $HttpProvider() {
102
102
103
103
// transform outgoing request data
104
104
transformRequest : function ( d ) {
105
- return isObject ( d ) ? toJson ( d ) : d ;
105
+ return isObject ( d ) && ! isFile ( d ) ? toJson ( d ) : d ;
106
106
} ,
107
107
108
108
// default headers
Original file line number Diff line number Diff line change @@ -564,6 +564,25 @@ describe('$http', function() {
564
564
$httpBackend . expect ( 'POST' , '/url' , 'string-data' ) . respond ( '' ) ;
565
565
$http ( { method : 'POST' , url : '/url' , data : 'string-data' } ) ;
566
566
} ) ;
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
+ } ) ;
567
586
} ) ;
568
587
569
588
You can’t perform that action at this time.
0 commit comments