From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Ivan Andrus <darthandrus@gmail.com>, 40693@debbugs.gnu.org
Subject: bug#40693: 28.0.50; json-encode-alist changes alist
Date: Sun, 19 Apr 2020 01:34:38 +0100 [thread overview]
Message-ID: <87a738jotd.fsf@tcd.ie> (raw)
In-Reply-To: <a10e47b4-314a-53b3-d478-adaaf32b5964@yandex.ru> (Dmitry Gutov's message of "Sat, 18 Apr 2020 20:29:03 +0300")
[-- Attachment #1: Type: text/plain, Size: 821 bytes --]
Dmitry Gutov <dgutov@yandex.ru> writes:
> How about this one?
>
> diff --git a/lisp/json.el b/lisp/json.el
> index 18d7fda882..b65884f913 100644
> --- a/lisp/json.el
> +++ b/lisp/json.el
> @@ -564,9 +564,10 @@ json-encode-alist
> "Return a JSON representation of ALIST."
> (when json-encoding-object-sort-predicate
> (setq alist
> - (sort alist (lambda (a b)
> - (funcall json-encoding-object-sort-predicate
> - (car a) (car b))))))
> + (sort (copy-sequence alist)
> + (lambda (a b)
> + (funcall json-encoding-object-sort-predicate
> + (car a) (car b))))))
> (format "{%s%s}"
> (json-join
> (json--with-indentation
LGTM. Perhaps add a test as well:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: json-tests.diff --]
[-- Type: text/x-diff, Size: 1010 bytes --]
diff --git a/test/lisp/json-tests.el b/test/lisp/json-tests.el
index 05837e83f9..9d7ffd5feb 100644
--- a/test/lisp/json-tests.el
+++ b/test/lisp/json-tests.el
@@ -269,10 +269,13 @@ test-json-encode-plist-with-sort-predicate
(should (equal (json-encode plist) "{\"a\":1,\"b\":2,\"c\":3}"))))
(ert-deftest test-json-encode-alist-with-sort-predicate ()
- (let ((alist '((:c . 3) (:a . 1) (:b . 2)))
- (json-encoding-object-sort-predicate 'string<)
- (json-encoding-pretty-print nil))
- (should (equal (json-encode alist) "{\"a\":1,\"b\":2,\"c\":3}"))))
+ (let* ((alist '((:c . 3) (:a . 1) (:b . 2)))
+ (clone (copy-sequence alist))
+ (json-encoding-object-sort-predicate #'string<)
+ (json-encoding-pretty-print nil))
+ (should (equal (json-encode alist) "{\"a\":1,\"b\":2,\"c\":3}"))
+ ;; Ensure sorting isn't destructive (bug#40693).
+ (should (equal alist clone))))
(ert-deftest test-json-encode-list ()
(let ((json-encoding-pretty-print nil))
[-- Attachment #3: Type: text/plain, Size: 59 bytes --]
Eli, would this be okay for emacs-27?
Thanks,
--
Basil
next prev parent reply other threads:[~2020-04-19 0:34 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-18 2:59 bug#40693: 28.0.50; json-encode-alist changes alist Ivan Andrus
2020-04-18 17:29 ` Dmitry Gutov
2020-04-18 21:00 ` Ivan Andrus
2020-04-18 23:13 ` Michael Heerdegen
2020-04-19 0:10 ` Dmitry Gutov
2020-04-19 0:29 ` Michael Heerdegen
2020-04-19 0:33 ` Basil L. Contovounesios
2020-04-19 0:34 ` Basil L. Contovounesios [this message]
2020-04-29 10:11 ` Basil L. Contovounesios
2020-04-29 10:30 ` Eli Zaretskii
2020-04-29 12:08 ` Dmitry Gutov
2020-04-29 12:21 ` Eli Zaretskii
2020-04-29 14:28 ` Dmitry Gutov
2020-04-29 14:40 ` Eli Zaretskii
2020-04-29 15:02 ` Dmitry Gutov
2020-04-29 15:07 ` Eli Zaretskii
2020-04-29 14:41 ` Basil L. Contovounesios
2020-05-18 1:24 ` Basil L. Contovounesios
2020-05-18 14:27 ` Eli Zaretskii
2020-05-18 22:50 ` Dmitry Gutov
2020-05-18 23:50 ` João Távora
2020-05-21 21:14 ` Basil L. Contovounesios
2020-05-21 22:16 ` João Távora
2020-05-22 14:54 ` Basil L. Contovounesios
2020-05-22 20:14 ` João Távora
2020-05-23 16:13 ` Basil L. Contovounesios
2020-05-23 19:40 ` João Távora
2020-05-23 22:41 ` Basil L. Contovounesios
2020-05-23 22:45 ` João Távora
2020-04-19 20:35 ` Paul Eggert
2020-04-19 21:01 ` Drew Adams
2020-04-19 22:14 ` Paul Eggert
2020-04-19 22:29 ` Michael Heerdegen
2020-04-19 23:59 ` Paul Eggert
2020-04-20 0:25 ` Michael Heerdegen
2020-04-20 0:32 ` Paul Eggert
2020-04-20 0:57 ` Michael Heerdegen
2020-04-20 2:55 ` Paul Eggert
2020-04-20 14:56 ` Eli Zaretskii
2020-04-20 5:45 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a738jotd.fsf@tcd.ie \
--to=contovob@tcd.ie \
--cc=40693@debbugs.gnu.org \
--cc=darthandrus@gmail.com \
--cc=dgutov@yandex.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).