-
Notifications
You must be signed in to change notification settings - Fork 86
Description
Hi, I find a rare case when utf-8 byte order mark (BOM) \xef\xbb\xbf involved.
Specifically, it will reject the json text when handling such case:
const char *s = "\xef\xbb\xbf{\"a\": [null, 1]}";
char *p;
int n;
int len = strlen(s);
int parsed_res = mjson_find(s, len, "$", &p, &n);
when we print the parsed_result
, the value is 0, indicating the input json text is invalid.
JSON message exchanged in different platforms (e.g., Desktop and Embedded device) may contain the BOM prefix,
and the specification suggests we can (not a must) ignore that prefix.
Meanwhile, I checked that multiple JSON implementations in other platforms such as https://github.com/nlohmann/json, https://github.com/alibaba/AliOS-Things/tree/master/components/cjson really ignored the prefix, and they correctly parsed the json text.
Therefore, it would be better if this implementation also ignore the BOM prefix, thus can provide better interoperability.