fix for empty key in objects - json2tsv - JSON to TSV converter
(HTM) git clone git://git.codemadness.org/json2tsv
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 65cdb7d2d32ee17246328b50c5a0ae4deab585fb
(DIR) parent 794f0a187d7ed4d72e60fbad7186e17f71ca23c4
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Tue, 15 Oct 2019 00:19:24 +0200
fix for empty key in objects
reproduce: {"a":1,"":"b"}
Diffstat:
M json2tsv.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
---
(DIR) diff --git a/json2tsv.c b/json2tsv.c
@@ -122,12 +122,11 @@ parsejson(void (*cb)(struct json_node *, size_t, const char *), const char **err
switch (c) {
case ':':
- nodes[depth].type = TYPE_PRIMITIVE;
- if (v) {
- if (!depth || nodes[depth - 1].type != TYPE_OBJECT) {
- *errstr = "object member, but not in an object";
- goto end;
- }
+ if (!depth || nodes[depth - 1].type != TYPE_OBJECT) {
+ *errstr = "object member, but not in an object";
+ goto end;
+ }
+ if (v || nodes[depth].type == TYPE_STRING) {
value[v] = '\0';
if (capacity(&(nodes[depth].name), &(nodes[depth].namesiz), v, 1) == -1)
goto end;
@@ -135,6 +134,7 @@ parsejson(void (*cb)(struct json_node *, size_t, const char *), const char **err
nodes[depth].name[v] = '\0';
v = 0;
}
+ nodes[depth].type = TYPE_PRIMITIVE;
break;
case '"':
v = 0;