Opened 12 years ago

Closed 12 years ago

Last modified 10 years ago

#5725 closed defect (fixed)

Parsing bad JSON text should throw an error

Reported by: kriszyp Owned by: Adam Peller
Priority: high Milestone: 1.1
Component: General Version: 1.0
Keywords: json Cc: alex
Blocked By: Blocking:

Description

When Dojo.fromJson is called with an invalid Json string, it returns the provided string when it should fail (throw an exception). It is irrational to return a wrong result rather than failing.

Attachments (2)

json.js (4.1 KB) - added by kriszyp 12 years ago.
patched json.js
json.2.js (1.2 KB) - added by kriszyp 12 years ago.
patched unit test for json.js

Download all attachments as: .zip

Change History (9)

Changed 12 years ago by kriszyp

Attachment: json.js added

patched json.js

Changed 12 years ago by kriszyp

Attachment: json.2.js added

patched unit test for json.js

comment:1 Changed 12 years ago by Adam Peller

Cc: alex added

we agree. technically, this would violate compatibility, but it's the right thing to do. thoughts?

comment:2 Changed 12 years ago by Frank Fortson

Sounds reasonable. I plan to post a patch to support complex queries in ItemFile?Store. It uses a string argument to "query", which works fine...except when dojo parses markup, it (I assume it is the parser) assumes the value of "query=" should be a json object and at some point dojo.fromJson is called. It now just prints a syntax error to console. Making the above change prior to finding where and possibly correcting the markup parsing will break the complex query patch. Guidance?

comment:3 Changed 12 years ago by bill

You could change ItemFileReadStore? to make query a string parameter, and then in the constructor manually convert it to a JS object. Take the parser out of the equation. For programmatic creation, still allow query to be specified as a string or an object and then in the constructor do { if ( typeof this.query == "String" )

comment:4 Changed 12 years ago by bill

PS: above comment by frankf is about #5735. Looking more closely at that bug, it's unclear that complex query support should use the query parameter or even be part of ItemFileReadStore. See #5735 for details.

comment:5 Changed 12 years ago by Adam Peller

Owner: changed from anonymous to Adam Peller

comment:6 Changed 12 years ago by Adam Peller

(In [12247]) throw for bad json. Refs #5725

comment:7 Changed 12 years ago by Adam Peller

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.