GNU bug report logs - #40693
28.0.50; json-encode-alist changes alist

Previous Next

Package: emacs;

Reported by: Ivan Andrus <darthandrus <at> gmail.com>

Date: Sat, 18 Apr 2020 03:01:02 UTC

Severity: normal

Tags: fixed, patch

Found in version 28.0.50

Fixed in version 28.1

Done: "Basil L. Contovounesios" <contovob <at> tcd.ie>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: Ivan Andrus <darthandrus <at> gmail.com>, 40693 <at> debbugs.gnu.org
Subject: bug#40693: 28.0.50; json-encode-alist changes alist
Date: Sun, 19 Apr 2020 01:13:04 +0200
Dmitry Gutov <dgutov <at> yandex.ru> writes:

> 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

Why?  Isn't this a classical example of modifiable code?  After some
iterations

(symbol-function 'fun-withdraw)

=>

(closure
 (t)
 (amount)
 (json-encode-alist
  (cons
   (cons 'tamount amount)
   '((const . some-constant)
     (tamount . 12)
     (tamount . 12)
     (tamount . 12)))))

So the problem is in the implementation of `fun-withdraw', not in that
of `json-encode-alist' or `sort'.

I mean, it's really an example of an ugly trap, but how is
`json-encode-alist' different from other functions working with lists
that would exploit the same problem?

Michael.




This bug report was last modified 5 years and 58 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.