Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix error writing strings containing chars outside the BMP

Signed-off-by: Stuart Sierra <mail@stuartsierra.com>
  • Loading branch information...
commit f0dd129f31b1f7cd26c3d9483696cade74d4e832 1 parent 11a9bfc
Andy Fingerhut authored February 20, 2012 stuartsierra committed March 07, 2012
2  src/main/clojure/clojure/data/json.clj
@@ -202,7 +202,7 @@
202 202
   (let [sb (StringBuilder. ^Integer (count s))]
203 203
     (.append sb \")
204 204
     (dotimes [i (count s)]
205  
-      (let [cp (Character/codePointAt s i)]
  205
+      (let [cp (int (.charAt s i))]
206 206
         (cond
207 207
          ;; Handle printable JSON escapes before ASCII
208 208
          (= cp 34) (.append sb "\\\"")
6  src/test/clojure/clojure/data/json_test.clj
@@ -27,6 +27,12 @@
27 27
 (deftest handles-unicode-escapes
28 28
   (is (= " \u0beb " (read-json "\" \\u0bEb \""))))
29 29
 
  30
+(deftest handles-unicode-outside-bmp
  31
+  (is (= "\"smiling face: \uD83D\uDE03\""
  32
+         (json-str "smiling face: \uD83D\uDE03" :escape-unicode false)))
  33
+  (is (= "\"smiling face: \\ud83d\\ude03\""
  34
+         (json-str "smiling face: \uD83D\uDE03" :escape-unicode true))))
  35
+
30 36
 (deftest handles-escaped-whitespace
31 37
   (is (= "foo\nbar" (read-json "\"foo\\nbar\"")))
32 38
   (is (= "foo\rbar" (read-json "\"foo\\rbar\"")))

0 notes on commit f0dd129

Please sign in to comment.
Something went wrong with that request. Please try again.