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
dc65edd519
commit
c6e9792188
2 changed files with 6 additions and 1 deletions
|
@ -580,7 +580,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;
|
||||
|
|
|
@ -127,6 +127,10 @@ static const char * const json_tests[] = {
|
|||
|
||||
"{" /* SHOULD_FAIL: test 10, missing open */
|
||||
"\"a\":123,\"b\":}"
|
||||
"}",
|
||||
|
||||
"{" /* test 13: float vs int */
|
||||
"\"a\": 1, \"b\": 1.0, \"c\": 1e-3, \"d\": 1e3"
|
||||
"}"
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue