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

Commit 9ff769a

Browse files
committed
allow to xhr.send the appropriate falsy HTTP request body (false, 0, "", null, undefined)
1 parent ffd8972 commit 9ff769a

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/ng/httpBackend.js

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

112-
if (post === false) {
113-
xhr.send(post);
114-
}
115-
else {
116-
xhr.send(post || null);
117-
}
112+
xhr.send(post);
118113
}
119114

120115
if (timeout > 0) {

test/ng/httpBackendSpec.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,21 @@ describe('$httpBackend', function() {
5050
expect(xhr.$$data).toBe(null);
5151
});
5252

53-
it('should pass false to send if false body is set', function() {
54-
$backend('GET', '/some-url', false, noop);
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);
5565
xhr = MockXhr.$$lastInstance;
5666

57-
expect(xhr.$$data).toBe(false);
67+
expect(isNaN(xhr.$$data)).toEqual(true);
5868
});
5969

6070
it('should call completion function with xhr.statusText if present', function() {

0 commit comments

Comments
 (0)