From 16cbc723007fc33c836362ce1dc126a718f12192 Mon Sep 17 00:00:00 2001 From: "Eirik S. Morland" Date: Fri, 1 Aug 2014 19:37:07 +0200 Subject: [PATCH 1/2] Support "ArrayBuffer" to be part of the string. --- lib/response.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index f83d761..f575330 100644 --- a/lib/response.js +++ b/lib/response.js @@ -104,7 +104,7 @@ Response.prototype.handle = function (res) { Response.prototype._emitData = function (res) { var respBody = this.getResponse(res); - if (respBody.toString().match(/ArrayBuffer/)) { + if (Object.prototype.toString.call(respBody) === '[object ArrayBuffer]') { this.emit('data', new Uint8Array(respBody, this.offset)); this.offset = respBody.byteLength; return; From 608b3e2a83911e6fa44d96e51adb16c5b5d742bb Mon Sep 17 00:00:00 2001 From: "Eirik S. Morland" Date: Fri, 1 Aug 2014 20:34:41 +0200 Subject: [PATCH 2/2] Add a test case for string with "ArrayBuffer" in them. --- test/request_url.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/request_url.js b/test/request_url.js index 1f58f2d..337c3e2 100644 --- a/test/request_url.js +++ b/test/request_url.js @@ -112,3 +112,17 @@ test('Test POST XHR2 types', function(t) { }; request.end(new global.FormData()); }); + +test('Test strings with "ArrayBuffer" in them', function(t) { + var Response = require('../lib/response'); + var res = new Response; + var testString = 'I am a string with the word ArrayBuffer'; + // Monkey patch response object. + res.emit = function(e, d) { + if (e === 'data') { + t.equal( d, testString, 'Emitted data should equal testString'); + t.end(); + } + }; + res.handle({readyState: 4, responseText: testString}); +});