Skip to content
Browse files

Fix error writing strings containing chars outside the BMP

Signed-off-by: Stuart Sierra <mail@stuartsierra.com>
  • Loading branch information...
1 parent 11a9bfc commit f0dd129f31b1f7cd26c3d9483696cade74d4e832 @jafingerhut jafingerhut committed with stuartsierra
Showing with 7 additions and 1 deletion.
  1. +1 −1 src/main/clojure/clojure/data/json.clj
  2. +6 −0 src/test/clojure/clojure/data/json_test.clj
View
2 src/main/clojure/clojure/data/json.clj
@@ -202,7 +202,7 @@
(let [sb (StringBuilder. ^Integer (count s))]
(.append sb \")
(dotimes [i (count s)]
- (let [cp (Character/codePointAt s i)]
+ (let [cp (int (.charAt s i))]
(cond
;; Handle printable JSON escapes before ASCII
(= cp 34) (.append sb "\\\"")
View
6 src/test/clojure/clojure/data/json_test.clj
@@ -27,6 +27,12 @@
(deftest handles-unicode-escapes
(is (= " \u0beb " (read-json "\" \\u0bEb \""))))
+(deftest handles-unicode-outside-bmp
+ (is (= "\"smiling face: \uD83D\uDE03\""
+ (json-str "smiling face: \uD83D\uDE03" :escape-unicode false)))
+ (is (= "\"smiling face: \\ud83d\\ude03\""
+ (json-str "smiling face: \uD83D\uDE03" :escape-unicode true))))
+
(deftest handles-escaped-whitespace
(is (= "foo\nbar" (read-json "\"foo\\nbar\"")))
(is (= "foo\rbar" (read-json "\"foo\\rbar\"")))

0 comments on commit f0dd129

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