From 9275c5204017517a15562fc36fd44ad301842a4e Mon Sep 17 00:00:00 2001 From: John Hoffman Date: Thu, 16 Apr 2015 09:27:11 -0600 Subject: [PATCH] fix($http): stop coercing falsy HTTP request bodies to null / empty body Closes #11552 --- src/ng/httpBackend.js | 2 +- test/ng/httpBackendSpec.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 4eb872cd5f11..8bfd85516807 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -109,7 +109,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc } } - xhr.send(post || null); + xhr.send(post); } if (timeout > 0) { diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js index 12ceed5beb01..abe40d176bff 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -50,6 +50,23 @@ describe('$httpBackend', function() { expect(xhr.$$data).toBe(null); }); + it('should pass the correct falsy value to send if falsy body is set (excluding NaN)', function() { + var values = [false, 0, "", null, undefined]; + angular.forEach(values, function(value) { + $backend('GET', '/some-url', value, noop); + xhr = MockXhr.$$lastInstance; + + expect(xhr.$$data).toBe(value); + }); + }); + + it('should pass NaN to send if NaN body is set', function() { + $backend('GET', '/some-url', NaN, noop); + xhr = MockXhr.$$lastInstance; + + expect(isNaN(xhr.$$data)).toEqual(true); + }); + it('should call completion function with xhr.statusText if present', function() { callback.andCallFake(function(status, response, headers, statusText) { expect(statusText).toBe('OK');