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

fix($http) Don't try to JSON.stringify FormData objects #10373

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"isWindow": false,
"isScope": false,
"isFile": false,
"isFormData": false,
"isBlob": false,
"isBoolean": false,
"isPromiseLike": false,
Expand Down
6 changes: 6 additions & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
isWindow: true,
isScope: true,
isFile: true,
isFormData: true,
isBlob: true,
isBoolean: true,
isPromiseLike: true,
Expand Down Expand Up @@ -566,6 +567,11 @@ function isFile(obj) {
}


function isFormData(obj) {
return toString.call(obj) === '[object FormData]';
}


function isBlob(obj) {
return toString.call(obj) === '[object Blob]';
}
Expand Down
2 changes: 1 addition & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function $HttpProvider() {

// transform outgoing request data
transformRequest: [function(d) {
return isObject(d) && !isFile(d) && !isBlob(d) ? toJson(d) : d;
return isObject(d) && !isFile(d) && !isBlob(d) && !isFormData(d) ? toJson(d) : d;
}],

// default headers
Expand Down
9 changes: 9 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,15 @@ describe('$http', function() {
$http({ method: 'POST', url: '/url', data: blob });
});

it('should ignore FormData objects', function() {
if (!window.FormData) return;

var formData = new FormData();
formData.append('angular', 'is great');

$httpBackend.expect('POST', '/url', '[object FormData]').respond('');
$http({ method: 'POST', url: '/url', data: formData });
});

it('should have access to request headers', function() {
$httpBackend.expect('POST', '/url', 'header1').respond(200);
Expand Down