We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Description When enabling the YYJSON_READ_ALLOW_INF_AND_NAN flag, the JSON read fails, returning an unexpected character error with code 6.
YYJSON_READ_ALLOW_INF_AND_NAN
unexpected character
6
char_is_number(*cur)
Additional context
Running the code below results in these two errors:
Array JSON read error: unexpected character. Code: 6, at position: 28
Object JSON read error: unexpected character. Code: 6, at position: 78
How to reproduce
yyjson_read_flag flg = YYJSON_READ_ALLOW_INF_AND_NAN; // // Read array with nan and inf values // char arr_str[] = "[1, 123e999, nan, NaN, NAN, inf, infinity, Infinity, INF, -inf, -infinity, -Infinity, -INF]"; size_t arr_str_len = strlen(arr_str); yyjson_read_err arr_err; yyjson_doc *arr_doc = yyjson_read_opts(arr_str, arr_str_len, flg, NULL, &arr_err); if (!arr_doc) { fprintf(stderr, "Array JSON read error: %s. Code: %u, at position: %ld\n", arr_err.msg, arr_err.code, arr_err.pos); } yyjson_doc_free(arr_doc); // // Read object with nan and inf values // char obj_str[] = "{\"small\": 1, \"large\": 123e999, \"nan1\": nan, \"nan2\": NaN, \"nan3\": NAN, \"inf1\": inf, \"inf2\": infinity, \"inf3\": Infinity, \"inf4\": INF, \"inf5\": -inf, \"inf6\": -infinity, \"inf7\": -Infinity, \"inf8\": -INF}"; size_t obj_str_len = strlen(obj_str); yyjson_read_err obj_err; yyjson_doc *obj_doc = yyjson_read_opts(obj_str, obj_str_len, flg, NULL, &obj_err); if (!obj_doc) { fprintf(stderr, "Object JSON read error: %s. Code: %u, at position: %ld\n", obj_err.msg, obj_err.code, obj_err.pos); } yyjson_doc_free(obj_doc);
Possible fix Replace all instances of: if (has_flag(ALLOW_INF_AND_NAN) && *cur == 'N') with: if (has_flag(ALLOW_INF_AND_NAN) && *cur == 'i' || *cur == 'I' || *cur == 'N')
if (has_flag(ALLOW_INF_AND_NAN) && *cur == 'N')
if (has_flag(ALLOW_INF_AND_NAN) && *cur == 'i' || *cur == 'I' || *cur == 'N')
The text was updated successfully, but these errors were encountered:
Fix negative infinity literals error: #64
84c683a
Thanks, fixed: 84c683a
Sorry, something went wrong.
No branches or pull requests
Description
When enabling the
YYJSON_READ_ALLOW_INF_AND_NAN
flag, the JSON read fails, returning anunexpected character
error with code6
.char_is_number(*cur)
check, and handled accordingly.Additional context
Running the code below results in these two errors:
Array JSON read error: unexpected character. Code: 6, at position: 28
Object JSON read error: unexpected character. Code: 6, at position: 78
How to reproduce
Possible fix
Replace all instances of:
if (has_flag(ALLOW_INF_AND_NAN) && *cur == 'N')
with:
if (has_flag(ALLOW_INF_AND_NAN) && *cur == 'i' || *cur == 'I' || *cur == 'N')
The text was updated successfully, but these errors were encountered: