aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2010-11-26 10:02:45 -0500
committerStuart Sierra <mail@stuartsierra.com>2010-11-26 10:02:45 -0500
commitd6f6ccfaeac03e35b1f9dbfa04424866cd9b2a41 (patch)
treec6503cc86434fe1e44b4ff287ffc070f43bec325 /modules
parenta579d18512eaa2e61483b664a02fe18e47ee2c08 (diff)
Handle quotes in JSON keys correctly; refs #98
Diffstat (limited to 'modules')
-rw-r--r--modules/json/src/main/clojure/clojure/contrib/json.clj4
-rw-r--r--modules/json/src/test/clojure/clojure/contrib/test_json.clj3
2 files changed, 4 insertions, 3 deletions
diff --git a/modules/json/src/main/clojure/clojure/contrib/json.clj b/modules/json/src/main/clojure/clojure/contrib/json.clj
index 0a07b59c..a69195ea 100644
--- a/modules/json/src/main/clojure/clojure/contrib/json.clj
+++ b/modules/json/src/main/clojure/clojure/contrib/json.clj
@@ -238,9 +238,7 @@
(let [[k v] (first x)]
(when (nil? k)
(throw (Exception. "JSON object keys cannot be nil/null")))
- (.print out \")
- (.print out (as-str k))
- (.print out \")
+ (write-json-string (as-str k) out)
(.print out \:)
(write-json v out))
(let [nxt (next x)]
diff --git a/modules/json/src/test/clojure/clojure/contrib/test_json.clj b/modules/json/src/test/clojure/clojure/contrib/test_json.clj
index c38dbc6a..a4290e5c 100644
--- a/modules/json/src/test/clojure/clojure/contrib/test_json.clj
+++ b/modules/json/src/test/clojure/clojure/contrib/test_json.clj
@@ -185,6 +185,9 @@
(deftest can-accept-eof
(is (= ::eof (read-json "" true false ::eof))))
+(deftest characters-in-map-keys-are-escaped
+ (is (= (json-str {"\"" 42}) "{\"\\\"\":42}")))
+
;;; Pretty-printer
(deftest pretty-printing