Fork me on GitHub
#clojurescript
<
2023-01-17
>
Ben Hammond12:01:26

I am wondering about safety of clojure.edn/read-string reading through https://cljs.github.io/api/clojure.edn/ it looks like • read-eval is not a thing in cljs • If I wanted extra data-readers then I would have to explicitly pass them in • therefore read-string is safe by default in cljs Is that a correct assumption. My data source is supposed to be trusted. but I would like to be careful

thheller12:01:49

yes, its safe. no eval anywhere

🙏 2
👍 2
dimovich13:01:10

Hello all. Trying to use tagged literals using data_readers.cljc, and getting different results when running from CLJ vs. CLJS. Here is a minimal repro: https://gist.github.com/dimovich/161c0ee8dfdedbd7c3fcf6f11024f6f4

p-himik14:01:50

clojure.core/read-string works differently, if I'm not mistaken it doesn't care about custom data readers. It works only because it's being smart about records. Your reader function is incorrect in general, and the CLJS code shows it - it ends up calling (circle {:p [0 0], :r 3}), which is why you end up seeing a map within the record with CLJS.

p-himik14:01:18

Correction to the above - clojure.core/read-string doesn't care about the reader when the tag has . in its name. If there are dots, the tag is considered to be a record.

dimovich14:01:36

@U2FRKM4TW Thank you. Was wondering why in Clojure the record was initialized without calling the constructor fn.

👍 2
dimovich14:01:21

And what would be the proper way to read it in CLJS? A wrapper fn that pulls the values out of the map and calls the constructor?

p-himik14:01:24

I'd use the map->Circle auto-generated function.

👍 2
dimovich21:01:41

Thank you for the suggestion. Works like a charm!

🎉 2