Skip to content

suggestion: handling the BOM in json text #55

@Dongmuliang

Description

@Dongmuliang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions