guard against null getResponseText()

Given the READY_STATE_CHANGE event can be trigged from for various
reasons and be in a situation where the response is not yet
written, this guards against a null value which is possible per
the specification:

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseText
This commit is contained in:
Jack Pearkes 2020-07-21 20:41:08 -07:00 committed by Stanley Cheung
parent 675deb6e34
commit 6ad62b1670
1 changed files with 2 additions and 1 deletions

View File

@ -141,7 +141,8 @@ class GrpcWebClientReadableStream {
contentType = contentType.toLowerCase();
if (googString.startsWith(contentType, 'application/grpc-web-text')) {
var responseText = self.xhr_.getResponseText();
// Ensure responseText is not null
var responseText = self.xhr_.getResponseText() || "";
var newPos = responseText.length - responseText.length % 4;
var newData = responseText.substr(self.pos_, newPos - self.pos_);
if (newData.length == 0) return;