entangle icon indicating copy to clipboard operation
entangle copied to clipboard

Clojurescript does not handle rich literal \space

Open rymndhng opened this issue 9 years ago • 2 comments

On the client

entangle.client=> (swap! textarea (fn [x] (str x " : I SAID HEY")))
"HEY YOU HOW YOU DOING! : I SAID HEY"
entangle.client=> Sending diff to ws: {:patch {:+ [[21 " " ":" " " "I" " " "S" "A" "I" "D" " " "H" "E" "Y"]], :- []}, :version 0}
GOT:{:version 0, :patch {:+ [[21 \space \: \space \I \space \S \A \I \D \space \H \E \Y]], :- []}}
GOT:{:version 1, :patch {:+ [], :- []}}

rymndhng avatar May 06 '15 04:05 rymndhng

ClojureScript seems to be unable to interpret \space properly in reader/read-string.

In Clojure: 
entangle.single=> (pr-str {:foo \space})
"{:foo \\space}"

Then, deserializing in ClojureScript:
entangle.client => (reader/read-string "{:foo \\space}")
#<Error: Map literal must contain an even number of forms>
Error: Map literal must contain an even number of forms
    at Function.cljs.reader.reader_error.cljs$core$IFn$_invoke$arity$variadic (http://localhost:10000/public/js/out/cljs/reader.js:156:8)
    at cljs$reader$reader_error (http://localhost:10000/public/js/out/cljs/reader.js:152:33)
    at cljs$reader$read_map (http://localhost:10000/public/js/out/cljs/reader.js:436:26)
    at cljs$reader$read (http://localhost:10000/public/js/out/cljs/reader.js:810:34)
    at cljs$reader$read_string (http://localhost:10000/public/js/out/cljs/reader.js:837:25)

Conversely, trying to serialize in ClojureScript and then deserializing in the server works:

Example 2:

ClojureScript: 
entangle.client=> (pr-str {:foo \space})
"{:foo \" \"}"

Reading in Clojure:
entangle.single=> (read-string "{:foo \" \"}")
{:foo " "}

rymndhng avatar Jun 05 '15 05:06 rymndhng

Another note:

In Clojure, they're not equivalent:

entangle.single=> (def a {:foo " "})
#'entangle.single/a
entangle.single=> a
{:foo " "}
entangle.single=> (def b {:foo \space})
#'entangle.single/b
entangle.single=> (= a b)
false

In ClojureScript, they are!

entangle.client=> (pr-str {:foo \space})
"{:foo \" \"}"
entangle.client=> (def a {:foo " "})
{:foo " "}
entangle.client=> (def b {:foo \space})
{:foo " "}
entangle.client=> (= a b)
true

rymndhng avatar Jun 05 '15 05:06 rymndhng