libplugin: don't turn non-string JSON ids into strings.

When called with `"id": 1` we replied with `"id": "1"`.  lightningd doesn't
actually care, but it's weird.

Copy the entire token: this way we don't have to special case anything.

Also, remove the doubled test in json_add_jsonstr.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-12-27 17:39:34 +10:30
parent 9ed138f5e5
commit 2d8fff6b57
5 changed files with 39 additions and 19 deletions

View File

@@ -206,7 +206,9 @@ const char *json_get_id(const tal_t *ctx,
const jsmntok_t *idtok = json_get_member(buffer, obj, "id");
if (!idtok)
return NULL;
return json_strdup(ctx, buffer, idtok);
return tal_strndup(ctx,
json_tok_full(buffer, idtok),
json_tok_full_len(idtok));
}
/*-----------------------------------------------------------------------------