From ca318b028f74a33a79c1c44e290a01916e7e772a Mon Sep 17 00:00:00 2001 From: Sam Clift Date: Tue, 14 Apr 2015 14:33:33 +0100 Subject: [PATCH] fix($http): stop $httpBackend coersion of falsy values to null before xhr.send() stop $httpBackend from potentially overriding false values to null when sending a falsy value to a web service via POST or PUT et al --- src/ng/httpBackend.js | 2 +- test/ng/httpBackendSpec.js | 7 +++++++ 2 files changed, 8 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..bcec2db3c0ab 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -50,6 +50,13 @@ describe('$httpBackend', function() { expect(xhr.$$data).toBe(null); }); + it('should pass false to send if false body is set', function() { + $backend('GET', '/some-url', false, noop); + xhr = MockXhr.$$lastInstance; + + expect(xhr.$$data).toBe(false); + }); + it('should call completion function with xhr.statusText if present', function() { callback.andCallFake(function(status, response, headers, statusText) { expect(statusText).toBe('OK');