diff options
| author | Philipp Stephani | 2017-12-19 00:04:29 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2017-12-24 13:52:30 +0100 |
| commit | 3455192777459a08a38b0adb311a76202e29f48d (patch) | |
| tree | aa20b6d6b54940814ee6dd2775b2b440333385ce /src | |
| parent | c7a50740273a338285abe7c9bb24a1f45928e02a (diff) | |
| download | emacs-3455192777459a08a38b0adb311a76202e29f48d.tar.gz emacs-3455192777459a08a38b0adb311a76202e29f48d.zip | |
JSON serialization: reject duplicate keys in hashtables
* src/json.c (lisp_to_json_toplevel_1): Reject duplicate keys in
hashtables.
* test/src/json-tests.el (json-serialize/object-with-duplicate-keys):
Add unit tests.
Diffstat (limited to 'src')
| -rw-r--r-- | src/json.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/json.c b/src/json.c index 689f6ac510e..c1daba199c3 100644 --- a/src/json.c +++ b/src/json.c | |||
| @@ -352,7 +352,12 @@ lisp_to_json_toplevel_1 (Lisp_Object lisp, json_t **json) | |||
| 352 | /* We can't specify the length, so the string must be | 352 | /* We can't specify the length, so the string must be |
| 353 | null-terminated. */ | 353 | null-terminated. */ |
| 354 | check_string_without_embedded_nulls (key); | 354 | check_string_without_embedded_nulls (key); |
| 355 | int status = json_object_set_new (*json, SSDATA (key), | 355 | const char *key_str = SSDATA (key); |
| 356 | /* Reject duplicate keys. These are possible if the hash | ||
| 357 | table test is not `equal'. */ | ||
| 358 | if (json_object_get (*json, key_str) != NULL) | ||
| 359 | wrong_type_argument (Qjson_value_p, lisp); | ||
| 360 | int status = json_object_set_new (*json, key_str, | ||
| 356 | lisp_to_json (HASH_VALUE (h, i))); | 361 | lisp_to_json (HASH_VALUE (h, i))); |
| 357 | if (status == -1) | 362 | if (status == -1) |
| 358 | /* FIXME: A failure here might also indicate that the | 363 | /* FIXME: A failure here might also indicate that the |