[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 58c8605: Only escape quotation mark, backslash and
From: |
Dmitry Gutov |
Subject: |
[Emacs-diffs] master 58c8605: Only escape quotation mark, backslash and cntrl U+0000 to U+001F |
Date: |
Wed, 25 Mar 2015 19:54:37 +0000 |
branch: master
commit 58c86059c60bc27e9eadba5735da5a40b47f6005
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Only escape quotation mark, backslash and cntrl U+0000 to U+001F
* lisp/json.el (json-special-chars): Don't treat `/' specially, there's
no need to.
(json-encode-string): Only escape quotation mark, backslash and
the control characters U+0000 to U+001F.
---
lisp/ChangeLog | 7 +++++++
lisp/json.el | 6 +++---
test/automated/json-tests.el | 4 ++--
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2d150ba..56c2b4c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2015-03-25 Dmitry Gutov <address@hidden>
+
+ * json.el (json-special-chars): Don't treat `/' specially, there's
+ no need to.
+ (json-encode-string): Only escape quotation mark, backslash and
+ the control characters U+0000 to U+001F.
+
2015-03-25 Artur Malabarba <address@hidden>
* emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
diff --git a/lisp/json.el b/lisp/json.el
index a1e9bb7..eaf8596 100644
--- a/lisp/json.el
+++ b/lisp/json.el
@@ -258,7 +258,6 @@ representation will be parsed correctly."
(defvar json-special-chars
'((?\" . ?\")
(?\\ . ?\\)
- (?/ . ?/)
(?b . ?\b)
(?f . ?\f)
(?n . ?\n)
@@ -313,8 +312,9 @@ representation will be parsed correctly."
(let ((l (length string))
(start 0)
res mb)
- ;; Skip over ASCIIish printable characters.
- (while (setq mb (string-match "[\"\\/\b\f\n\r\t]\\|[^ -~]" string start))
+ ;; Only escape quotation mark, backslash and the control
+ ;; characters U+0000 to U+001F (RFC 4627, ECMA-404).
+ (while (setq mb (string-match "[\"\\[:cntrl:]]" string start))
(let* ((c (aref string mb))
(special (rassq c json-special-chars)))
(push (substring string start mb) res)
diff --git a/test/automated/json-tests.el b/test/automated/json-tests.el
index 881c237..fd89b7a 100644
--- a/test/automated/json-tests.el
+++ b/test/automated/json-tests.el
@@ -35,8 +35,8 @@
(ert-deftest json-encode-string-with-special-chars ()
(should (equal (json-encode-string "a\n\fb")
"\"a\\n\\fb\""))
- (should (equal (json-encode-string "\nasdфывfgh\t")
- "\"\\nasd\\u0444\\u044b\\u0432fgh\\t\"")))
+ (should (equal (json-encode-string "\nasdфыв\u001f\u007ffgh\t")
+ "\"\\nasdфыв\\u001f\u007ffgh\\t\"")))
(ert-deftest json-read-string-with-special-chars ()
(should (equal (json-read-from-string
"\"\\nasd\\u0444\\u044b\\u0432fgh\\t\"")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 58c8605: Only escape quotation mark, backslash and cntrl U+0000 to U+001F,
Dmitry Gutov <=