* [PATCH] json-encode-char bug?
@ 2012-09-27 10:22 Takafumi Arakaki
2012-09-27 13:13 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Takafumi Arakaki @ 2012-09-27 10:22 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 409 bytes --]
Dear Emacs devs,
I am using json.el for my IPython notebook client in Emacs [1].
json.el works very well but I think I found a bug. It prints
character 161 (Non-breaking space) as a raw character, but it causes
error when parsing it in Python. I think it should be escaped in
\uNNNN form. I attached a patch to fix this problem.
[1] https://github.com/tkf/emacs-ipython-notebook
Best,
Takafumi Arakaki
[-- Attachment #2: json.patch --]
[-- Type: application/octet-stream, Size: 427 bytes --]
diff --git a/lisp/json.el b/lisp/json.el
index f1ee3a5..7d1c96a 100644
--- a/lisp/json.el
+++ b/lisp/json.el
@@ -315,7 +315,7 @@ representation will be parsed correctly."
(control-char
(format "\\%c" control-char))
;; ASCIIish printable character
- ((and (> char 31) (< char 161))
+ ((and (> char 31) (< char 160))
(format "%c" char))
;; Fallback: UCS code point in \uNNNN form
(t
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] json-encode-char bug?
2012-09-27 10:22 [PATCH] json-encode-char bug? Takafumi Arakaki
@ 2012-09-27 13:13 ` Stefan Monnier
2012-09-27 17:32 ` Takafumi Arakaki
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2012-09-27 13:13 UTC (permalink / raw)
To: Takafumi Arakaki; +Cc: emacs-devel
> json.el works very well but I think I found a bug. It prints
> character 161 (Non-breaking space) as a raw character, but it causes
NBSP is actually 160, but I see what you mean.
> ;; ASCIIish printable character
> - ((and (> char 31) (< char 161))
> + ((and (> char 31) (< char 160))
Actually, ASCII only goes up to 127, so I've changed the 161 to 128
(now that I think about it, ASCII 127 is DEL which isn't very printable
either so maybe I should have replaced it with 127).
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] json-encode-char bug?
2012-09-27 13:13 ` Stefan Monnier
@ 2012-09-27 17:32 ` Takafumi Arakaki
2012-09-27 22:55 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Takafumi Arakaki @ 2012-09-27 17:32 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
On Thu, Sep 27, 2012 at 3:13 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> Actually, ASCII only goes up to 127, so I've changed the 161 to 128
> (now that I think about it, ASCII 127 is DEL which isn't very printable
> either so maybe I should have replaced it with 127).
Thank you very much for the quick fix. Indeed,
json.dumps(unichr(127)) returns '"\\u007f"' in Python, so I guess it's
better to change 128 to 127.
In browser, JSON.stringify(String.fromCharCode(127)) returns '""',
which is raw code I guess. But
JSON.stringify(String.fromCharCode(160)) returns '" "', so maybe this
is my JS console's problem (node and google chrome) or they are
encoded at different stage.
Takafumi
PS: Sorry to send it twice to you, Stefan. I meant to sent it to emacs-devel.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] json-encode-char bug?
2012-09-27 17:32 ` Takafumi Arakaki
@ 2012-09-27 22:55 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2012-09-27 22:55 UTC (permalink / raw)
To: Takafumi Arakaki; +Cc: emacs-devel
> Thank you very much for the quick fix. Indeed,
> json.dumps(unichr(127)) returns '"\\u007f"' in Python, so I guess it's
> better to change 128 to 127.
Thanks, done,
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-09-27 22:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-27 10:22 [PATCH] json-encode-char bug? Takafumi Arakaki
2012-09-27 13:13 ` Stefan Monnier
2012-09-27 17:32 ` Takafumi Arakaki
2012-09-27 22:55 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).