summaryrefslogtreecommitdiff
path: root/lisp/json.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2017-02-05 16:28:53 +0000
committerAlan Mackenzie <acm@muc.de>2017-02-05 16:28:53 +0000
commitd5514332d4a6092673ce1f78fadcae0c57f7be64 (patch)
tree1780337154904dcfad8ecfa76614b47c082160dd /lisp/json.el
parentcecc25c68f5a1834c356e18259aa2af402a70ce1 (diff)
parentde3336051ef74e0c3069374ced5b5fc7bb9fba15 (diff)
downloademacs-d5514332d4a6092673ce1f78fadcae0c57f7be64.tar.gz
Merge branch 'master' into comment-cache
Diffstat (limited to 'lisp/json.el')
-rw-r--r--lisp/json.el17
1 files changed, 16 insertions, 1 deletions
diff --git a/lisp/json.el b/lisp/json.el
index fdac8d9a826..b2ac356641b 100644
--- a/lisp/json.el
+++ b/lisp/json.el
@@ -1,6 +1,6 @@
;;; json.el --- JavaScript Object Notation parser / generator -*- lexical-binding: t -*-
-;; Copyright (C) 2006-2016 Free Software Foundation, Inc.
+;; Copyright (C) 2006-2017 Free Software Foundation, Inc.
;; Author: Edward O'Connor <ted@oconnor.cx>
;; Version: 1.4
@@ -363,6 +363,10 @@ representation will be parsed correctly."
;; String parsing
+(defun json--decode-utf-16-surrogates (high low)
+ "Return the code point represented by the UTF-16 surrogates HIGH and LOW."
+ (+ (lsh (- high #xD800) 10) (- low #xDC00) #x10000))
+
(defun json-read-escaped-char ()
"Read the JSON string escaped character at point."
;; Skip over the '\'
@@ -372,6 +376,17 @@ representation will be parsed correctly."
(cond
(special (cdr special))
((not (eq char ?u)) char)
+ ;; Special-case UTF-16 surrogate pairs,
+ ;; cf. https://tools.ietf.org/html/rfc7159#section-7. Note that
+ ;; this clause overlaps with the next one and therefore has to
+ ;; come first.
+ ((looking-at
+ (rx (group (any "Dd") (any "89ABab") (= 2 (any "0-9A-Fa-f")))
+ "\\u" (group (any "Dd") (any "C-Fc-f") (= 2 (any "0-9A-Fa-f")))))
+ (json-advance 10)
+ (json--decode-utf-16-surrogates
+ (string-to-number (match-string 1) 16)
+ (string-to-number (match-string 2) 16)))
((looking-at "[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]")
(let ((hex (match-string 0)))
(json-advance 4)