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

Commit 0c80df2

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 3141dbf commit 0c80df2

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
@@ -98,6 +98,25 @@ describe('$httpBackend', function() {
9898
expect(callback).toHaveBeenCalledOnce();
9999
});
100100

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

0 commit comments

Comments
 (0)