Skip to content

Commit

Permalink
CLJS-1573: Self-host: Invalid UTF escaping in cljs-in-cljs
Browse files Browse the repository at this point in the history
Zero-pad \u escapes
  • Loading branch information
mfikes authored and swannodette committed Feb 23, 2016
1 parent c59e957 commit 16666f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/clojure/cljs/compiler.cljc
Expand Up @@ -132,8 +132,10 @@
9 "\\t"
(if (< 31 cp 127)
c ; Print simple ASCII characters
#?(:clj (format "\\u%04X" cp)
:cljs (str "\\u" (.toString cp 16))))))) ; Any other character is Unicode
#?(:clj (format "\\u%04X" cp) ; Any other character is Unicode
:cljs (let [unpadded (.toString cp 16)
pad (subs "0000" (.-length unpadded))]
(str "\\u" pad unpadded)))))))

(defn- escape-string [^CharSequence s]
(let [sb #?(:clj (StringBuilder. (count s))
Expand Down
34 changes: 34 additions & 0 deletions src/test/self/self_host/test.cljs
Expand Up @@ -240,6 +240,40 @@
(is (nil? value))
(is (= "if-let requires a vector for its binding at line 1 " (ex-message (ex-cause error)))))))

(deftest test-CLJS-1573
(cljs/compile-str st
"\"90°\""
nil
{:eval node-eval
:context :expr}
(fn [{:keys [error value]}]
(is (nil? error))
(is (= "\"90\\u00b0\"" value))))
(cljs/compile-str st
"\"Ϊ\""
nil
{:eval node-eval
:context :expr}
(fn [{:keys [error value]}]
(is (nil? error))
(is (= "\"\\u03aa\"" value))))
(cljs/compile-str st
"\"\""
nil
{:eval node-eval
:context :expr}
(fn [{:keys [error value]}]
(is (nil? error))
(is (= "\"\\u1234\"" value))))
(cljs/eval-str st
"\"90°\""
nil
{:eval node-eval
:context :expr}
(fn [{:keys [error value]}]
(is (nil? error))
(is (= "90°" value)))))

#_(deftest test-eval-str-with-require
(async done
(let [l (latch 3 done)]
Expand Down

0 comments on commit 16666f3

Please sign in to comment.