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

Commit

Permalink
fix($httpBackend): prevent DOM err due to dereferencing .responseText
Browse files Browse the repository at this point in the history
If responseType is defined and the request fails for one reason or another
the .response property returned falsy value which caused dereferencing of
.responseText. If the responseType was a blob or document then an error
was thrown.

To prevent this, I'm checking for responseType first and based on that
dereferencing .response or .responseText.

We need to keep on checking .responseText because that's the original XHR
response api that is still needed for IE8 and 9.

Closes #1922
  • Loading branch information
IgorMinar committed Feb 24, 2013
1 parent d44ca19 commit 509ec74
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
}
// end of the workaround.

completeRequest(callback, status || xhr.status, xhr.response || xhr.responseText,
responseHeaders);
// responseText is the old-school way of retrieving response (supported by IE8 & 9)
// response and responseType properties were introduced in XHR Level2 spec (supported by IE10)
completeRequest(callback,
status || xhr.status,
(xhr.responseType ? xhr.response : xhr.responseText),
responseHeaders);
}
};

Expand Down

2 comments on commit 509ec74

@jamie-pate
Copy link

Choose a reason for hiding this comment

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

I'm looking at a bug here.
On ie8 (ie8 standards) xhr looks like this for me:
{responseType:"json", responseText:'{"status": "success", ...}', response: undefined}

(maybe a better check would be 'response' in xhr)?? that will test for existence, instead of falsy...

in ie8 i'm seeing this:
'response' in xhr -> false

@jamie-pate
Copy link

Choose a reason for hiding this comment

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

Seems like xhr.responseType is being set manually on line 104:

xhr.responseType = responseType;

Please sign in to comment.