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

Commit

Permalink
fix($httpBackend): send null when post-data is undefined
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gkalpak committed Sep 3, 2015
1 parent c3a654b commit 6f39f10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ng/httpBackend.js
Expand Up @@ -109,7 +109,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
}
}

xhr.send(post);
xhr.send(isUndefined(post) ? null : post);
}

if (timeout > 0) {
Expand Down
20 changes: 11 additions & 9 deletions test/ng/httpBackendSpec.js
Expand Up @@ -44,21 +44,23 @@ describe('$httpBackend', function() {
});

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

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;
it('should pass the correct falsy value to send if falsy body is set (excluding undefined, NaN)',
function() {
var values = [false, 0, "", null];
angular.forEach(values, function(value) {
$backend('GET', '/some-url', value, noop);
xhr = MockXhr.$$lastInstance;

expect(xhr.$$data).toBe(value);
});
});
expect(xhr.$$data).toBe(value);
});
}
);

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

1 comment on commit 6f39f10

@gkalpak
Copy link
Member Author

@gkalpak gkalpak commented on 6f39f10 Sep 3, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #12745 (I messed up the commit message).

Please sign in to comment.