mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
lejp: E implies float
Since eg, 1e-3 is a float without needing a decimal point, let's just generally take it that anything with the exponent token is a float, ie, 1e3 is also a float despite it can be expressed as an integer. This seems right also because E is itself not valid in an integer. https://github.com/warmcat/libwebsockets/issues/3308
This commit is contained in:
parent
a74362ffdd
commit
1fccae47ed
2 changed files with 21 additions and 1 deletions
|
@ -617,7 +617,8 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len)
|
|||
}
|
||||
|
||||
ctx->buf[ctx->npos] = '\0';
|
||||
if (ctx->f & LEJP_SEEN_POINT) {
|
||||
if (ctx->f & (LEJP_SEEN_POINT | LEJP_SEEN_EXP)) {
|
||||
/* 0.001 or 1E-3 are both floats, take 1E3 as float too */
|
||||
if (ctx->pst[ctx->pst_sp].callback(ctx,
|
||||
LEJPCB_VAL_NUM_FLOAT))
|
||||
goto reject_callback;
|
||||
|
|
|
@ -137,6 +137,10 @@ static const char * const json_tests[] = {
|
|||
"{" /* test 12: test 11 but done with LEJP_FLAG_FEAT_OBJECT_INDEXES */
|
||||
"\"array1\": [[\"a\", \"b\", \"b1\"], [\"c\", \"d\", \"d1\"]],"
|
||||
"\"array2\": [[\"e\", \"f\", \"f1\"], [\"g\", \"h\", \"h1\"]]"
|
||||
"}",
|
||||
|
||||
"{" /* test 13: float vs int */
|
||||
"\"a\": 1, \"b\": 1.0, \"c\": 1e-3, \"d\": 1e3"
|
||||
"}"
|
||||
};
|
||||
|
||||
|
@ -438,6 +442,20 @@ static struct lejp_results {
|
|||
{ 15, 1, 2, { 1, }, "array2[]", "h1" },
|
||||
{ 17, 1, 0, { 1, }, "array2[]", "h1" },
|
||||
{ 3, 1, 0, { 1, }, "array2[]", "h1" },
|
||||
}, r13[] = {
|
||||
{ 0, 0, 0, { }, "", "h1" },
|
||||
{ 2, 0, 0, { }, "", "h1" },
|
||||
{ 16, 0, 0, { 0, }, "", "h1" },
|
||||
{ 5, 0, 0, { 0, }, "a", "h1" },
|
||||
{ 73, 0, 0, { 0, }, "a", "1" },
|
||||
{ 5, 0, 0, { 1, }, "b", "1" },
|
||||
{ 74, 0, 0, { 1, }, "b", "1.0" },
|
||||
{ 5, 0, 0, { 2, }, "c", "1.0" },
|
||||
{ 74, 0, 0, { 2, }, "c", "1e-3" },
|
||||
{ 5, 0, 0, { 3, }, "d", "1e-3" },
|
||||
{ 74, 0, 0, { 3, }, "d", "1e3" },
|
||||
{ 17, 0, 0, { 3, }, "d", "1e3" },
|
||||
{ 3, 0, 0, { 3, }, "d", "1e3" },
|
||||
};
|
||||
|
||||
static const char * const tok[] = {
|
||||
|
@ -469,6 +487,7 @@ struct lejp_results_pkg {
|
|||
{ r12, LWS_ARRAY_SIZE(r12), tok_test11, LWS_ARRAY_SIZE(tok_test11),
|
||||
LEJP_FLAG_FEAT_LEADING_WC |
|
||||
LEJP_FLAG_FEAT_OBJECT_INDEXES },
|
||||
{ r13, LWS_ARRAY_SIZE(r13), tok, LWS_ARRAY_SIZE(tok), 0 },
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue