diff options
author | Nikias Bassen | 2022-04-06 01:04:50 +0200 |
---|---|---|
committer | Nikias Bassen | 2022-04-06 01:04:50 +0200 |
commit | d25e919f29078127b0305f88cdcbc33a798c5d90 (patch) | |
tree | 5cd4b3d75e2960f1c1d6c99fbeb55cba3cae44af /src | |
parent | 106c4ee7f53ef800a82fce9638f29756e8b78640 (diff) | |
download | libplist-d25e919f29078127b0305f88cdcbc33a798c5d90.tar.gz libplist-d25e919f29078127b0305f88cdcbc33a798c5d90.tar.bz2 |
Skip whitespace to properly detect format in plist_from_memory()
Diffstat (limited to 'src')
-rw-r--r-- | src/plist.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plist.c b/src/plist.c index 9f3c8f4..78e71da 100644 --- a/src/plist.c +++ b/src/plist.c @@ -199,10 +199,15 @@ PLIST_API plist_err_t plist_from_memory(const char *plist_data, uint32_t length, } if (plist_is_binary(plist_data, length)) { res = plist_from_bin(plist_data, length, plist); - } else if (plist_data[0] == '[' || plist_data[0] == '{') { - res = plist_from_json(plist_data, length, plist); } else { - res = plist_from_xml(plist_data, length, plist); + /* skip whitespace before checking */ + uint32_t pos = 0; + while (pos < length && ((plist_data[pos] == ' ') || (plist_data[pos] == '\t') || (plist_data[pos] == '\r') || (plist_data[pos] == '\n'))) pos++; + if (plist_data[pos] == '[' || plist_data[pos] == '{') { + res = plist_from_json(plist_data, length, plist); + } else { + res = plist_from_xml(plist_data, length, plist); + } } return res; } |