Skip to content

Commit c6e9792

Browse files
ribes96lws-team
authored andcommitted
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. #3308
1 parent dc65edd commit c6e9792

File tree

2 files changed

+6
-1
lines changed
  • lib/misc
  • minimal-examples/api-tests/api-test-lejp

2 files changed

+6
-1
lines changed

lib/misc/lejp.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len)
580580
}
581581

582582
ctx->buf[ctx->npos] = '\0';
583-
if (ctx->f & LEJP_SEEN_POINT) {
583+
if (ctx->f & (LEJP_SEEN_POINT | LEJP_SEEN_EXP)) {
584+
/* 0.001 or 1E-3 are both floats, take 1E3 as float too */
584585
if (ctx->pst[ctx->pst_sp].callback(ctx,
585586
LEJPCB_VAL_NUM_FLOAT))
586587
goto reject_callback;

minimal-examples/api-tests/api-test-lejp/main.c

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ static const char * const json_tests[] = {
127127

128128
"{" /* SHOULD_FAIL: test 10, missing open */
129129
"\"a\":123,\"b\":}"
130+
"}",
131+
132+
"{" /* test 13: float vs int */
133+
"\"a\": 1, \"b\": 1.0, \"c\": 1e-3, \"d\": 1e3"
130134
"}"
131135
};
132136

0 commit comments

Comments
 (0)