diff --git a/src/main/clojure/clojure/data/json.clj b/src/main/clojure/clojure/data/json.clj index dbf8282..ec23180 100644 --- a/src/main/clojure/clojure/data/json.clj +++ b/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 "\\\"") diff --git a/src/test/clojure/clojure/data/json_test.clj b/src/test/clojure/clojure/data/json_test.clj index 1805928..e3555cf 100644 --- a/src/test/clojure/clojure/data/json_test.clj +++ b/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\"")))