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

Commit

Permalink
fix($http): should not read statusText on IE<10 when request is aborted
Browse files Browse the repository at this point in the history
Commit 1d2414c introduced a regression by retrieving the statusText
of an aborted xhr request. This breaks IE9, which throws a c00c023f
error when accessing properties of an aborted xhr request. The fix
is similar to the one in commit 6f1050d.
  • Loading branch information
khellang authored and IgorMinar committed Jun 30, 2014
1 parent 3141dbf commit 0c80df2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
// Safari respectively.
if (xhr && xhr.readyState == 4) {
var responseHeaders = null,
response = null;
response = null,
statusText = '';

if(status !== ABORTED) {
responseHeaders = xhr.getAllResponseHeaders();
Expand All @@ -91,11 +92,17 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
response = ('response' in xhr) ? xhr.response : xhr.responseText;
}

// Accessing statusText on an aborted xhr object will
// throw an 'c00c023f error' in IE9 and lower, don't touch it.
if (!(status === ABORTED && msie < 10)) {
statusText = xhr.statusText;
}

completeRequest(callback,
status || xhr.status,
response,
responseHeaders,
xhr.statusText || '');
statusText);
}
};

Expand Down
19 changes: 19 additions & 0 deletions test/ng/httpBackendSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ describe('$httpBackend', function() {
expect(callback).toHaveBeenCalledOnce();
});

it('should not touch xhr.statusText when request is aborted on IE9 or lower', function() {
callback.andCallFake(function(status, response, headers, statusText) {
expect(statusText).toBe((!msie || msie >= 10) ? 'OK' : '');
});

$backend('GET', '/url', null, callback, {}, 2000);
xhr = MockXhr.$$lastInstance;
spyOn(xhr, 'abort');

fakeTimeout.flush();
expect(xhr.abort).toHaveBeenCalledOnce();

xhr.status = 0;
xhr.readyState = 4;
xhr.statusText = 'OK';
xhr.onreadystatechange();
expect(callback).toHaveBeenCalledOnce();
});

it('should call completion function with empty string if not present', function() {
callback.andCallFake(function(status, response, headers, statusText) {
expect(statusText).toBe('');
Expand Down

0 comments on commit 0c80df2

Please sign in to comment.