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

Commit 6f39f10

Browse files
committed
fix($httpBackend): send null when post-data is undefined
IE11 (and maybe others) converts an `undefined` argument to `xhr.send()` to string (`'undefined'`) for certain request methods (e.g. DELETE). This causes the request to appear having a body, when it shouldn't. Fixes #12141 Fixes #12739 Closes
1 parent c3a654b commit 6f39f10

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/ng/httpBackend.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
109109
}
110110
}
111111

112-
xhr.send(post);
112+
xhr.send(isUndefined(post) ? null : post);
113113
}
114114

115115
if (timeout > 0) {

test/ng/httpBackendSpec.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,23 @@ describe('$httpBackend', function() {
4444
});
4545

4646
it('should pass null to send if no body is set', function() {
47-
$backend('GET', '/some-url', null, noop);
47+
$backend('GET', '/some-url', undefined, noop);
4848
xhr = MockXhr.$$lastInstance;
4949

5050
expect(xhr.$$data).toBe(null);
5151
});
5252

53-
it('should pass the correct falsy value to send if falsy body is set (excluding NaN)', function() {
54-
var values = [false, 0, "", null, undefined];
55-
angular.forEach(values, function(value) {
56-
$backend('GET', '/some-url', value, noop);
57-
xhr = MockXhr.$$lastInstance;
53+
it('should pass the correct falsy value to send if falsy body is set (excluding undefined, NaN)',
54+
function() {
55+
var values = [false, 0, "", null];
56+
angular.forEach(values, function(value) {
57+
$backend('GET', '/some-url', value, noop);
58+
xhr = MockXhr.$$lastInstance;
5859

59-
expect(xhr.$$data).toBe(value);
60-
});
61-
});
60+
expect(xhr.$$data).toBe(value);
61+
});
62+
}
63+
);
6264

6365
it('should pass NaN to send if NaN body is set', function() {
6466
$backend('GET', '/some-url', NaN, noop);

0 commit comments

Comments
 (0)