mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
fix($http): should not read statusText on IE<10 when request is aborted
Commit1d2414cintroduced 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 commit6f1050d.
This commit is contained in:
committed by
Igor Minar
parent
3141dbf179
commit
0c80df21b6
@@ -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();
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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('');
|
||||
|
||||
Reference in New Issue
Block a user