-
-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaks on a clojure.lang.Keyword
with a space in it
#251
Comments
I highly doubt this is valid EDN. Looking at the printed output, there is no way to tell that |
Well, as far as I can tell, EDN is not formally specified... You are correct that (edn/read-string "{:Foo bar 3}") => throws However, (clojure.core/prn-str {(keyword "Foo bar") 3}) ;; => "{:Foo bar 3}\n"
(taoensso.encore/pr-edn {(keyword "Foo bar") 3}) ;; => "{:Foo bar 3}"
(-> {(keyword "Foo bar") 3}
taoensso.encore/pr-edn
edn/read-string) ;; => throws exception which is a recipe for pain... since I imagine it's a fairly common pattern. I ran into it because we read a clojure map from MongoDB and try to pass it over a websocket. I think it'd be good if |
Actually, it looks like the trouble is with (with-out-str (clojure.core/pr (keyword "Foo bar"))) ;; => ":Foo bar" that doesn't seem right... |
See the previous discussions here: http://stackoverflow.com/questions/11282806/clojure-map-key-with-spaces-in-the-key-name I highly recommend not trying to use keywords with spaces in them. You are liable to run into all sorts of strange issues if you keep going down this road, especially if you're wanting to transfer them between client and server. It looks like Transit supports it, but that doesn't mean that everything else in your app will. My recommendations, in order:
|
Thanks for this, @danielcompton. For posterity: I switched to using sente's TransitPacker and that's working nicely. I never intentionally created a keyword with a space in it... it does seem like a bad idea. However, since some libraries (monger in my case) default to converting keys from other formats into clojure keywords, they will sometimes produce keywords with spaces in them. |
for example
cannot be sent with sente, it'll complain of "Bad package" (map literal must contain even number of forms)
Is there a proper way to express that in EDN? It's valid in Clojure and ClojureScript
The text was updated successfully, but these errors were encountered: