Ticket #5725 (closed defect: fixed)

Opened 17 months ago

Last modified 17 months ago

Parsing bad JSON text should throw an error

Reported by: kriszyp Owned by: peller
Priority: normal Milestone: 1.1
Component: General Version: 1.0
Severity: normal Keywords: json
Cc: alex

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

json.js (4.1 kB) - added by kriszyp 17 months ago.
patched json.js
json.2.js (1.2 kB) - added by kriszyp 17 months ago.
patched unit test for json.js

Change History

Changed 17 months ago by kriszyp

patched json.js

Changed 17 months ago by kriszyp

patched unit test for json.js

Changed 17 months ago by peller

  • cc alex added

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

Changed 17 months ago by frankf

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?

Changed 17 months 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" )

Changed 17 months 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.

Changed 17 months ago by peller

  • owner changed from anonymous to peller

Changed 17 months ago by peller

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

Changed 17 months ago by peller

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.