Zulu-Inuoe / jzon

A correct and safe(er) JSON RFC 8259 reader/writer with sane defaults.
MIT License
151 stars 14 forks source link

bug when `stringifying` exponent markers #45

Closed jsulmont closed 1 year ago

jsulmont commented 1 year ago

Hi Firstly thank you for this library! There is probably a bug when stringifying floats with (any) exponent markers:

(jzon:stringify 1.0d0)                ;; =>  "^@.0"
(jzon:stringify 12.0d0))            ;; =>   "^@1.0"
(jzon:stringify 123456.0s0)     ;; =>   "^@12345.0"

;; 

I'll try to come up with a PR; but in the meantime, would appreciate if anyone has an idea. Thank you!!

Zulu-Inuoe commented 1 year ago

This is very odd and looks like some kid of encoding issue.. Can I ask for details on where you're running this? OS and version information? Also the version of SBCL

jsulmont commented 1 year ago

@Zulu-Inuoe Yes sorry. I am using the latest SBCL (2.3.4) on MacOS silicon

Zulu-Inuoe commented 1 year ago

Okay. Could you share the output at the repl when you eval (map 'list #'char-code "e+-.0123456789") ? It might be that the encoding differs for some reason.

jsulmont commented 1 year ago

Here:

* (map 'list #'char-code "e+-.0123456789")
(101 43 45 46 48 49 50 51 52 53 54 55 56 57)
Zulu-Inuoe commented 1 year ago

Hey @jsulmont thank you so much for reporting this. I had a bad implementation of the printer when writing numbers without exponent or decimal parts. I can't believe I hadn't run into this before, since it's been there from the beginning. https://github.com/Zulu-Inuoe/jzon/pull/46 should fix this