+2015-03-25 Dmitry Gutov <dgutov@yandex.ru>
+
+ * 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 <bruce.connor.am@gmail.com>
* emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
(defvar json-special-chars
'((?\" . ?\")
(?\\ . ?\\)
- (?/ . ?/)
(?b . ?\b)
(?f . ?\f)
(?n . ?\n)
(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)
(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\"")