Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions test/request_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
});