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

Commit e04a887

Browse files
johnhoffmancaitp
authored andcommitted
fix($http): stop coercing falsy HTTP request bodies to null / empty body
Closes #11552 Closes #11593
1 parent 08411cf commit e04a887

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
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 || null);
112+
xhr.send(post);
113113
}
114114

115115
if (timeout > 0) {

test/ng/httpBackendSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ describe('$httpBackend', function() {
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;
58+
59+
expect(xhr.$$data).toBe(value);
60+
});
61+
});
62+
63+
it('should pass NaN to send if NaN body is set', function() {
64+
$backend('GET', '/some-url', NaN, noop);
65+
xhr = MockXhr.$$lastInstance;
66+
67+
expect(isNaN(xhr.$$data)).toEqual(true);
68+
});
69+
5370
it('should call completion function with xhr.statusText if present', function() {
5471
callback.andCallFake(function(status, response, headers, statusText) {
5572
expect(statusText).toBe('OK');

0 commit comments

Comments
 (0)