From ab3e40b37c482f049801fa47f153289111801cf8 Mon Sep 17 00:00:00 2001 From: Ramiro Polla Date: Sun, 2 Dec 2018 00:23:30 +0100 Subject: [PATCH] json_object_deep_copy: fix deep copy of strings containing '\0' --- json_object.c | 2 +- tests/test_deep_copy.c | 1 + tests/test_deep_copy.expected | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/json_object.c b/json_object.c index 1d9a53c..e3c5744 100644 --- a/json_object.c +++ b/json_object.c @@ -1388,7 +1388,7 @@ int json_c_shallow_copy_default(json_object *src, json_object *parent, const cha break; case json_type_string: - *dst = json_object_new_string(get_string_component(src)); + *dst = json_object_new_string_len(get_string_component(src), src->o.c_string.len); break; case json_type_object: diff --git a/tests/test_deep_copy.c b/tests/test_deep_copy.c index 7a6e63f..53b8a84 100644 --- a/tests/test_deep_copy.c +++ b/tests/test_deep_copy.c @@ -18,6 +18,7 @@ static const char *json_str1 = " \"GlossDiv\": {" " \"title\": \"S\"," " \"null_obj\": null, " +" \"null_str\": \" \\u0000 \"," " \"GlossList\": {" " \"GlossEntry\": {" " \"ID\": \"SGML\"," diff --git a/tests/test_deep_copy.expected b/tests/test_deep_copy.expected index d009e94..ef65b64 100644 --- a/tests/test_deep_copy.expected +++ b/tests/test_deep_copy.expected @@ -13,6 +13,7 @@ Printing JSON objects for visual inspection "GlossDiv":{ "title":"S", "null_obj":null, + "null_str":" \u0000 ", "GlossList":{ "GlossEntry":{ "ID":"SGML", -- 2.50.1