diff options
| author | Mattias EngdegÄrd | 2024-09-08 20:02:34 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2024-09-08 20:02:34 +0200 |
| commit | e55e2e1c6baebbd105f930fa553ec65c74a3000d (patch) | |
| tree | c171c29f7bcfb8a4a52e74e641506aaf9a2b960d /src | |
| parent | 89c99891b2b3ab087cd7e824cef391ef26800ab4 (diff) | |
| download | emacs-e55e2e1c6baebbd105f930fa553ec65c74a3000d.tar.gz emacs-e55e2e1c6baebbd105f930fa553ec65c74a3000d.zip | |
Make json-serialize always return a unibyte string (bug#70007)
The JSON format is defined as a byte sequence and will always be used as
such, so returning a multibyte string makes little sense.
* src/json.c (json_out_to_string): Remove.
(Fjson_serialize): Return unibyte string.
* test/src/json-tests.el (json-serialize/roundtrip)
(json-serialize/roundtrip-scalars, json-serialize/string):
Update tests.
* doc/lispref/text.texi (Parsing JSON): Document.
* etc/NEWS: Announce.
Diffstat (limited to 'src')
| -rw-r--r-- | src/json.c | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/src/json.c b/src/json.c index 21066d21328..41566f8369b 100644 --- a/src/json.c +++ b/src/json.c | |||
| @@ -559,16 +559,6 @@ json_out_something (json_out_t *jo, Lisp_Object obj) | |||
| 559 | wrong_type_argument (Qjson_value_p, obj); | 559 | wrong_type_argument (Qjson_value_p, obj); |
| 560 | } | 560 | } |
| 561 | 561 | ||
| 562 | static Lisp_Object | ||
| 563 | json_out_to_string (json_out_t *jo) | ||
| 564 | { | ||
| 565 | /* FIXME: should this be a unibyte or multibyte string? | ||
| 566 | Right now we make a multibyte string for test compatibility, | ||
| 567 | but we are really encoding so unibyte would make more sense. */ | ||
| 568 | ptrdiff_t nchars = jo->size - jo->chars_delta; | ||
| 569 | return make_multibyte_string (jo->buf, nchars, jo->size); | ||
| 570 | } | ||
| 571 | |||
| 572 | static void | 562 | static void |
| 573 | json_serialize (json_out_t *jo, Lisp_Object object, | 563 | json_serialize (json_out_t *jo, Lisp_Object object, |
| 574 | ptrdiff_t nargs, Lisp_Object *args) | 564 | ptrdiff_t nargs, Lisp_Object *args) |
| @@ -596,7 +586,7 @@ json_serialize (json_out_t *jo, Lisp_Object object, | |||
| 596 | 586 | ||
| 597 | DEFUN ("json-serialize", Fjson_serialize, Sjson_serialize, 1, MANY, | 587 | DEFUN ("json-serialize", Fjson_serialize, Sjson_serialize, 1, MANY, |
| 598 | NULL, | 588 | NULL, |
| 599 | doc: /* Return the JSON representation of OBJECT as a string. | 589 | doc: /* Return the JSON representation of OBJECT as a unibyte string. |
| 600 | 590 | ||
| 601 | OBJECT is translated as follows: | 591 | OBJECT is translated as follows: |
| 602 | 592 | ||
| @@ -629,7 +619,7 @@ usage: (json-serialize OBJECT &rest ARGS) */) | |||
| 629 | specpdl_ref count = SPECPDL_INDEX (); | 619 | specpdl_ref count = SPECPDL_INDEX (); |
| 630 | json_out_t jo; | 620 | json_out_t jo; |
| 631 | json_serialize (&jo, args[0], nargs - 1, args + 1); | 621 | json_serialize (&jo, args[0], nargs - 1, args + 1); |
| 632 | return unbind_to (count, json_out_to_string (&jo)); | 622 | return unbind_to (count, make_unibyte_string (jo.buf, jo.size)); |
| 633 | } | 623 | } |
| 634 | 624 | ||
| 635 | DEFUN ("json-insert", Fjson_insert, Sjson_insert, 1, MANY, | 625 | DEFUN ("json-insert", Fjson_insert, Sjson_insert, 1, MANY, |