Skip to content

Commit

Permalink
lejp: E implies float
Browse files Browse the repository at this point in the history
    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.

    #3308
  • Loading branch information
ribes96 authored and lws-team committed Jan 10, 2025
1 parent dc65edd commit c6e9792
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/misc/lejp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions minimal-examples/api-tests/api-test-lejp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"}"
};

Expand Down

0 comments on commit c6e9792

Please sign in to comment.