summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2023-01-08 05:19:28 +0100
committerGravatar Nikias Bassen2023-01-08 05:19:28 +0100
commitd19997a3deb68585ea4080615ca3502e0d6930f8 (patch)
tree0f141c93bfa81191c794fd79902c7f5cb334f694
parent307fcc5f95f06ecd6fb7e3769450a923b8aaba26 (diff)
downloadlibplist-d19997a3deb68585ea4080615ca3502e0d6930f8.tar.gz
libplist-d19997a3deb68585ea4080615ca3502e0d6930f8.tar.bz2
JSON: Only allow to convert PLIST_DICT or PLIST_ARRAY node to JSON
-rw-r--r--src/jplist.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/jplist.c b/src/jplist.c
index d12540e..f4adf2f 100644
--- a/src/jplist.c
+++ b/src/jplist.c
@@ -395,6 +395,11 @@ PLIST_API int plist_to_json(plist_t plist, char **json, uint32_t* length, int pr
return PLIST_ERR_INVALID_ARG;
}
+ if (!PLIST_IS_DICT(plist) && !PLIST_IS_ARRAY(plist)) {
+ PLIST_JSON_WRITE_ERR("plist data is not valid for JSON format\n");
+ return PLIST_ERR_FORMAT;
+ }
+
res = node_estimate_size(plist, &size, 0, prettify);
if (res < 0) {
return res;
@@ -413,6 +418,9 @@ PLIST_API int plist_to_json(plist_t plist, char **json, uint32_t* length, int pr
*length = 0;
return res;
}
+ if (prettify) {
+ str_buf_append(outbuf, "\n", 1);
+ }
str_buf_append(outbuf, "\0", 1);