Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@jafingerhut jafingerhut authored stuartsierra committed
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\"")))
Please sign in to comment.
Something went wrong with that request. Please try again.