Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#17117 closed defect (fixed)

dojo/request/xhr doesn't properly handle falsy response.data

Reported by: Scott Hunter Owned by: Bryan Forbes
Priority: high Milestone: 1.8.11
Component: IO Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

If I use xhr with handleAs : 'json', and the response JSON entirely consists of:

false

then the promise resolves to the original response text "false" instead of the JSON parsed, boolean value false. I tracked it down to request/util, where the promise is chained through a function that does:

return response.data || response.text;

The mistake here is using || instead of an undefined check. Even if response.data is falsy, it should be used in preference to the original response text.

Change History (5)

comment:1 Changed 7 years ago by bill

Component: GeneralIO
Owner: set to Bryan Forbes

comment:2 Changed 5 years ago by iDo

Little bump on this one. The problem is still valid.

I created a PR for fixing it: https://github.com/dojo/dojo/pull/155

([PATCH][CLA] can be added to the title)

comment:3 Changed 5 years ago by dylan

Milestone: tbd1.11
Priority: undecidedhigh
Resolution: fixed
Status: newclosed

Fixed via db66e918cd5a736fa4023741ace82e1bdc0fb612 in 1.11

Note the patch does not cleanly backport, so if we want to backport it to 1.10, etc., please provide a pull request against that branch because 1.10 and earlier have their tests using DOH rather than Intern. Thanks!

comment:4 Changed 5 years ago by iDo

@dylan I created a PR for the backport: https://github.com/dojo/dojo/pull/156

comment:5 Changed 5 years ago by dylan

Milestone: 1.111.8.11

Backported to 1.10, 1.9, and 1.8.

Note: See TracTickets for help on using tickets.