Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#18816 closed defect (fixed)

dojo/request/util/parseArgs() corrupts ArrayBuffer, Blob and File data sent with POST requests

Reported by: patatruc Owned by: dylan
Priority: high Milestone: 1.11.2
Component: IO Version: 1.11.0-rc5
Keywords: Cc:
Blocked By: Blocking:

Description

Hello,

With XMLHttpRequest, you can send an ArrayBuffer?, a Blob or a File to a server :

var xhr = new XMLHttpRequest();
xhr.open("POST", req, true);
var arrbuf = new ArrayBuffer(3);
var i8array = new Int8Array(arrbuf);
for (var i = 0; i < 3; i++) i8array[i] = i;
xhr.send(arrbuf);

It sends [0, 1, 2] to the server.

The same with dojo/request *does not work* :

var arrbuf = new ArrayBuffer(3);
var i8array = new Int8Array(arrbuf);
for (var i = 0; i < 3; i++) i8array[i] = i;
request(req, { method: "POST", data: arrbuf });

It sends an *empty string* to the server. There are similar dysfunctions with Blobs and Files.

The problem lies in the parseArgs function, request/util.js, line 130 :

exports.parseArgs = function parseArgs(url, options, skipData){
	var data = options.data,
		query = options.query;

	if(data && !skipData){
		if(typeof data === 'object'){ /* <===== HERE ======== */
			options.data = ioQuery.objectToQuery(data);
		}
	}

typeof data === 'object' returns true if data contains a Blob, an ArrayBuffer? or a File, the data is then wrongly handled as if it were a name/value mapping object.

To avoid this error, this test should be replaced with something like this :

if(typeof data === 'object' &&
	!(data instanceof ArrayBuffer || data instanceof Blob || data instanceof File) {

Change History (5)

comment:1 Changed 4 years ago by dylan

Owner: set to dylan
Status: newassigned

I'll look into landing a fix for this, but realistically, after 1.11.0 lands.

comment:2 Changed 4 years ago by dylan

Component: GeneralIO
Milestone: tbd1.11.2
Priority: undecidedhigh

comment:3 Changed 4 years ago by Michael J Van Sickle

Submitted PR 214 (https://github.com/dojo/dojo/pull/214) to address this

comment:4 Changed 4 years ago by Dylan Schiemann <dylan@…>

Resolution: fixed
Status: assignedclosed

In 825332e/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:5 Changed 4 years ago by Dylan Schiemann <dylan@…>

In 5a5b224c/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.