all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattias.engdegard@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: casouri@gmail.com, 70007@debbugs.gnu.org
Subject: bug#70007: [PATCH] native JSON encoder
Date: Thu, 28 Mar 2024 21:59:38 +0100	[thread overview]
Message-ID: <2CF47DA5-A65B-47C4-A28A-6FEE1469BD13@gmail.com> (raw)
In-Reply-To: <8634sbijfx.fsf@gnu.org>

27 mars 2024 kl. 20.05 skrev Eli Zaretskii <eliz@gnu.org>:

>>> This rejects unibyte non-ASCII strings, AFAU, in which case I suggest
>>> to think whether we really want that.  E.g., why is it wrong to encode
>>> a string to UTF-8, and then send it to JSON?
>> 
>> The way I see it, that would break the JSON abstraction: it transports strings of Unicode characters, not strings of bytes.
> 
> What's the difference?  AFAIU, JSON expects UTF-8 encoded strings, and
> whether that is used as a sequence of bytes or a sequence of
> characters is in the eyes of the beholder: the bytestream is the same,
> only the interpretation changes.

Well no -- JSON transports Unicode strings: the JSON serialiser takes a Unicode string as input and outputs a byte sequence; the JSON parser takes a byte sequence and returns a Unicode string (assuming we are just interested in strings).

That the transport format uses UTF-8 is unrelated; if the user hands an encoded byte sequence to us then it seems more likely that it's a mistake. After all, it cannot have come from a received JSON message.

I think it was just an another artefact of the old implementation. That code incorrectly used encode_string_utf_8 even on non-ASCII unibyte strings and trusted Jansson to validate the result. That resulted in a lot of wasted work and some strange strings getting accepted.

While it's theoretically possible that there are users with code relying on this behaviour, I can't find any evidence for it in the packages that I've looked at.

> I didn't suggest to decode the input string, not at all.  I suggested
> to allow unibyte strings, and process them just like you process
> pure-ASCII strings, leaving it to the caller to make sure the string
> has only valid UTF-8 sequences.

Users of this raw-bytes-input feature (if they exist at all) previously had their input validated by Jansson. While mistakes would probably be detected at the other end I'm not sure it's a good idea.

>  Forcing callers to decode such
> strings is IMO too harsh and largely unjustified.

We usually force them to do so in most other contexts. To take a random example, `princ` doesn't work with encoded strings. But it's rarely a problem.

Let's see how testing goes. We'll find a solution no matter what, pass-through or separate slow-path validation, if it turns out that we really need to after all.






  reply	other threads:[~2024-03-28 20:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 15:33 bug#70007: [PATCH] native JSON encoder Mattias Engdegård
2024-03-26 16:46 ` Eli Zaretskii
2024-03-27 12:46   ` Mattias Engdegård
2024-03-27 15:49     ` Mattias Engdegård
2024-03-27 17:40       ` Eli Zaretskii
2024-03-27 18:57         ` Mattias Engdegård
2024-03-27 19:05           ` Eli Zaretskii
2024-03-28 20:59             ` Mattias Engdegård [this message]
2024-03-29  6:04               ` Eli Zaretskii
2024-03-30 11:41                 ` Mattias Engdegård
2024-03-30 13:22                   ` Eli Zaretskii
2024-03-30 14:22                     ` Mattias Engdegård
2024-03-30 16:14                       ` Richard Copley
2024-03-30 16:40                         ` Eli Zaretskii
2024-03-30 23:29                           ` Richard Copley
2024-03-30 16:45                         ` Andy Moreton
2024-03-30 20:36                           ` Corwin Brust
2024-03-30 16:37                       ` Eli Zaretskii
2024-03-30 20:21                         ` Mattias Engdegård
2024-04-02 14:13                       ` Mattias Engdegård
2024-04-02 16:13                         ` Eli Zaretskii
2024-04-02 17:19                           ` Mattias Engdegård
2024-03-28 19:16   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2CF47DA5-A65B-47C4-A28A-6FEE1469BD13@gmail.com \
    --to=mattias.engdegard@gmail.com \
    --cc=70007@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=eliz@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.