Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($http): Do not serialize File object
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Feb 26, 2012
1 parent 230f29d commit 5b0d068
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';}

Expand Down
2 changes: 1 addition & 1 deletion src/service/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/service/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
});
});


Expand Down

0 comments on commit 5b0d068

Please sign in to comment.