naomijub / edn-rs

[DEPRECATED]: Crate to parse and emit EDN
https://crates.io/crates/edn-rs
MIT License
81 stars 14 forks source link

Handling of non-dec numbers (eg "0x2a") #100

Closed Grinkers closed 1 year ago

Grinkers commented 1 year ago

According to the spec, this isn't an issue. Here's a very relavent discussion I found while looking into this. https://github.com/edn-format/edn/issues/47

here is some examples of read-string

(clojure.edn/read-string "0x2a") -> 42
(clojure.edn/read-string "2r101010") -> 42
(clojure.edn/read-string "36r16") -> 42

As far as this crate is concerned, I think maybe it should be more liberal than the spec for some convenient patterns. In particular, "0x" being supported in both rust and clojure.edn/read-string. "2r" vs "0b" is a bit harder of a thing and could be a future nightmare. Alternatively, perhaps this crate should be more apparent with off-spec integers so these doesn't succeed.

assert_eq!(Edn::from_str("0x2a").unwrap().to_int().unwrap(), 0);
assert_eq!(Edn::from_str("42FOOBAR9000").unwrap().to_int().unwrap(), 42);
naomijub commented 1 year ago

Seems interesting, are you able to open a PR for this?