data.json

Double "positive infinity" value leads to json strings that can not be decoded

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:

Description

If you put a Double/POSITIVE_INFINITY as a value somewhere in your Clojure-collection and convert it to JSON then it will become impossible to decode that JSON back to Clojure-collection. Double/POSITIVE_INFINITY is encoded as "Infinity" string. When you try to parse that JSON, you get an Exception "Exception JSON error (unexpected character): I clojure.data.json/-read".

Can't say whether this really is a bug, but the thing that looks bad is that I couldn't decode what I encoded with the same library, it's not always "x == (read-str (write-str x))".

Here is a simple test to reproduce this behaviour:

> (require '[clojure.data.json :as json])
nil
> (json/write-str Double/POSITIVE_INFINITY)
"Infinity"
> (json/read-str (json/write-str Double/POSITIVE_INFINITY))
Exception JSON error (unexpected character): I  clojure.data.json/-read (json.clj:226)

Originally I encountered this problem with clojure.data.json v. 0.1.2:

(json/read-json (json/json-str Double/POSITIVE_INFINITY))
Exception JSON error (unexpected character): I  clojure.data.json/read-json-reader (json.clj:158)

Activity

Stuart Sierra made changes -
Field Original Value New Value
Resolution Completed [ 1 ]
Assignee Stuart Sierra [ stuart.sierra ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: