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

Commit 31ae3e7

Browse files
khellangIgorMinar
authored andcommitted
fix($http): should not read statusText on IE<10 when request is aborted
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.
1 parent b59b04f commit 31ae3e7

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/ng/httpBackend.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
8181
// Safari respectively.
8282
if (xhr && xhr.readyState == 4) {
8383
var responseHeaders = null,
84-
response = null;
84+
response = null,
85+
statusText = '';
8586

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

95+
// Accessing statusText on an aborted xhr object will
96+
// throw an 'c00c023f error' in IE9 and lower, don't touch it.
97+
if (!(status === ABORTED && msie < 10)) {
98+
statusText = xhr.statusText;
99+
}
100+
94101
completeRequest(callback,
95102
status || xhr.status,
96103
response,
97104
responseHeaders,
98-
xhr.statusText || '');
105+
statusText);
99106
}
100107
};
101108

test/ng/httpBackendSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ describe('$httpBackend', function() {
9292
expect(callback).toHaveBeenCalledOnce();
9393
});
9494

95+
it('should not touch xhr.statusText when request is aborted on IE9 or lower', function() {
96+
callback.andCallFake(function(status, response, headers, statusText) {
97+
expect(statusText).toBe((!msie || msie >= 10) ? 'OK' : '');
98+
});
99+
100+
$backend('GET', '/url', null, callback, {}, 2000);
101+
xhr = MockXhr.$$lastInstance;
102+
spyOn(xhr, 'abort');
103+
104+
fakeTimeout.flush();
105+
expect(xhr.abort).toHaveBeenCalledOnce();
106+
107+
xhr.status = 0;
108+
xhr.readyState = 4;
109+
xhr.statusText = 'OK';
110+
xhr.onreadystatechange();
111+
expect(callback).toHaveBeenCalledOnce();
112+
});
113+
95114
it('should call completion function with empty string if not present', function() {
96115
callback.andCallFake(function(status, response, headers, statusText) {
97116
expect(statusText).toBe('');

0 commit comments

Comments
 (0)