From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#40693: 28.0.50; json-encode-alist changes alist Date: Wed, 29 Apr 2020 11:11:38 +0100 Message-ID: <87mu6utxd1.fsf@tcd.ie> References: <87a738jotd.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="12900"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Ivan Andrus , 40693@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 29 12:12:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jTjhL-0003BH-On for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Apr 2020 12:12:11 +0200 Original-Received: from localhost ([::1]:48046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTjhK-0001D3-RG for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Apr 2020 06:12:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38688) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTjhD-0001Bj-Pm for bug-gnu-emacs@gnu.org; Wed, 29 Apr 2020 06:12:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTjhD-0006FO-6X for bug-gnu-emacs@gnu.org; Wed, 29 Apr 2020 06:12:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59155) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jTjhC-0006FJ-Qd for bug-gnu-emacs@gnu.org; Wed, 29 Apr 2020 06:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jTjhB-0007GE-Kr for bug-gnu-emacs@gnu.org; Wed, 29 Apr 2020 06:12:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 Apr 2020 10:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40693 X-GNU-PR-Package: emacs Original-Received: via spool by 40693-submit@debbugs.gnu.org id=B40693.158815511027890 (code B ref 40693); Wed, 29 Apr 2020 10:12:01 +0000 Original-Received: (at 40693) by debbugs.gnu.org; 29 Apr 2020 10:11:50 +0000 Original-Received: from localhost ([127.0.0.1]:42468 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jTjgz-0007Fm-O9 for submit@debbugs.gnu.org; Wed, 29 Apr 2020 06:11:49 -0400 Original-Received: from mail-pj1-f52.google.com ([209.85.216.52]:51788) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jTjgx-0007FV-Iy for 40693@debbugs.gnu.org; Wed, 29 Apr 2020 06:11:48 -0400 Original-Received: by mail-pj1-f52.google.com with SMTP id mq3so584173pjb.1 for <40693@debbugs.gnu.org>; Wed, 29 Apr 2020 03:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=0PW8X/D9mgcgfPLKam1disCxZtfckp2CuUrgnhN6lXE=; b=otNKGmWRgYkA3mm2srwmLvRqfbVsHsQ+yjGplk0LXqyElS6njCab1FYOJhvGrAdYF5 sFkXlQJQtATHTlgLlDtOx0LGRT7LpLCnRgeu2ODn+esh3AMjabYRn+hb9lEy9Kj1bcyh jC0SwiLgLa3zcKd66Yfq9S9betS6NYwPu7CYKgAQsO6hy2ouc3uLnCQdXJGIiB6t3PAa 2Eo2brD3CI/CxuMdE91eSKIpJ1MkItobSRfoRZ1FhWWqGtLG6PT04E/6B7GLTcr5XLnZ DV63w7Er5yUlK0B+aPANvVkS7krrQYg8bXovr0YoBRKAdcEGu1sSpC0vDtC3zQo0B6N6 fJBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=0PW8X/D9mgcgfPLKam1disCxZtfckp2CuUrgnhN6lXE=; b=IrwECUDCAImFDYOVbYAN30S3DvgwaEemEBapqDPNyHbHdVjGqhcNfvq1oEVOU1IftB 7ew1oNg9Bo95vXtAHfpoczNOZUb2bxJJeMvXG2PbQn5jKCitYadxfXy5gfzbpEAaVb4I hYqbfrO4tGbyY71Nn0+4tYLdteQ+A9jpd10UlSYYCljQk+nubQpguC6nj9bNx4uCTrV0 tMQmn3K2BCDLLafev/50vg5G/dOKojIECI4HZBs4eWzP48eGzML1MutRrjSI7kF0V+xv L7FEga1uDdjaBIsfIJFzMbdgoC0xVHpxFrbbtWVZhhjlA8aFqzFNsImadhcj+6Oa0irs Hm3g== X-Gm-Message-State: AGi0Pua2jsycBSikmELsC/AZwCoj3e1X7+4BcVt53UkAxNWfvmQ0S2Gi LYhT+AgFB7BY3F/nHn2LUxLolQ== X-Google-Smtp-Source: APiQypLzdu9eVzaqqTUyIrgWBpdx77ccNZ4pny3Au4UjFtVTq5gj21phECQQV6KKjY64N19aqW4wjg== X-Received: by 2002:a17:90a:d17:: with SMTP id t23mr2370507pja.77.1588155101581; Wed, 29 Apr 2020 03:11:41 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:92bd:1bfd:38fc:fae2]) by smtp.gmail.com with ESMTPSA id w11sm794304pfq.100.2020.04.29.03.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 03:11:40 -0700 (PDT) In-Reply-To: <87a738jotd.fsf@tcd.ie> (Basil L. Contovounesios's message of "Sun, 19 Apr 2020 01:34:38 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:179296 Archived-At: "Basil L. Contovounesios" writes: > Dmitry Gutov 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: > > 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)) > > > Eli, would this be okay for emacs-27? Any chance of getting this fix in? Thanks, -- Basil