Skip to content
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

encoder unicode bug #2

Open
cades opened this issue Apr 23, 2013 · 1 comment
Open

encoder unicode bug #2

cades opened this issue Apr 23, 2013 · 1 comment

Comments

@cades
Copy link

cades commented Apr 23, 2013

json:encode-json-to-string output ALL character as ASCII code. Non-ASCII become escape sequence. There's a post on stack overflow describing this: http://stackoverflow.com/questions/12304702/cl-json-encodes-unicode-chars-by-outputting-their-unicode-escape-string-in-ascii

After comment out some code, it works as I expected. However, I known't know whether those code are essential. Maybe doing this introduce another bug:

(defun write-json-chars (s stream)
  "Write JSON representations (chars or escape sequences) of
characters in string S to STREAM."
  (loop for ch across s
     for code = (char-code ch)
     with special
     if (setq special (car (rassoc ch +json-lisp-escaped-chars+)))
       do (write-char #\\ stream) (write-char special stream)
     else;; if (< #x1f code #x7f)
       do (write-char ch stream)
     ;; else
     ;;   do (let ((special '#.(rassoc-if #'consp +json-lisp-escaped-chars+)))
     ;;        (destructuring-bind (esc . (width . radix)) special
     ;;          (format stream "\\~C~V,V,'0R" esc radix width code)))
    ))
@rpgoldman
Copy link
Contributor

AFAICT this is not actually a bug, judging from the Stack Overflow
discussion. According to the RFC, pointed to by this Stack Overflow
discussion
http://stackoverflow.com/questions/4901133/json-and-escaping-characters,
we are licensed to escape all the unicode characters.

I would prefer we keep this behavior for simplicity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants