fix($http): Do not serialize File object

This commit is contained in:
Vojta Jina 2012-02-25 18:49:54 -08:00
parent 230f29d0a7
commit 5b0d068358
3 changed files with 25 additions and 1 deletions

View file

@ -417,6 +417,11 @@ function isScope(obj) {
}
function isFile(obj) {
return toString.apply(obj) === '[object File]';
}
function isBoolean(value) {return typeof value == $boolean;}
function isTextNode(node) {return nodeName_(node) == '#text';}

View file

@ -102,7 +102,7 @@ function $HttpProvider() {
// transform outgoing request data
transformRequest: function(d) {
return isObject(d) ? toJson(d) : d;
return isObject(d) && !isFile(d) ? toJson(d) : d;
},
// default headers

View file

@ -564,6 +564,25 @@ describe('$http', function() {
$httpBackend.expect('POST', '/url', 'string-data').respond('');
$http({method: 'POST', url: '/url', data: 'string-data'});
});
it('should ignore File objects', function() {
var file = {
some: true,
// $httpBackend compares toJson values by default,
// we need to be sure it's not serialized into json string
test: function(actualValue) {
return this === actualValue;
}
};
// I'm really sorry for doing this :-D
// Unfortunatelly I don't know how to trick toString.apply(obj) comparison
spyOn(window, 'isFile').andReturn(true);
$httpBackend.expect('POST', '/some', file).respond('');
$http({method: 'POST', url: '/some', data: file});
});
});