Skip to content

json BUGFIX exponent numbers with a leading zero - #2633

Merged
michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:json-exp-leading-zero
Nov 16, 2026
Merged

michalvasko merged 1 commit into
CESNET:develfrom
affan-arch:json-exp-leading-zero

Conversation

@affan-arch

Copy link
Copy Markdown

lyjson_exp_number() rewrites JSON numbers that carry an exponent into plain decimal text before the value reaches the type plugins. for the 0.xxxEn shape where the new decimal point lands inside the digits, the leading-zero branch put the point at n - 1 instead of n minus the zeros it skips, and didn't reserve a byte for it, so the terminator cut off the last digit: 0.25E2 turned into 2. and 0.5E1 into a bare ., and integer leaves reject them even though 2.5E1 goes through as 25. the nastier case is when two or more zeros get skipped and the point drops out entirely, so 0.0034E3 (3.4) comes out as 34 and a uint8 leaf happily stores 34, same for 0.00255E4 (25.5) stored as 255. anydata keeps the converted text as well, so {"a":0.5E1,"c":-0.00642406E+4} is printed back as {"a":.,"c":-642.40}, which is neither valid JSON nor the value that was sent. i noticed it while diffing the lexer output against python's Decimal over random numbers; with the fix 200k of them match, and the new cases in test_number fail on the current tree. the change stays inside that one branch since the other branches already agreed with Decimal.

For a number such as 0.xxxEn whose new decimal point falls inside the
digits, lyjson_exp_number() placed the point at n - 1 instead of n
minus the skipped leading zeros and reserved no byte for it, so the
last digit was cut off. 0.25E2 became "2." and 0.5E1 became ".", and
0.0034E3 (3.4) became "34", which an integer leaf accepts. Anydata
content kept the converted text, printing -0.00642406E+4 as -642.40.
@michalvasko
michalvasko changed the base branch from master to devel November 16, 2026 10:34
@michalvasko

Copy link
Copy Markdown
Member

Thanks, merging but to devel, we do not accept PRs into master.

@michalvasko
michalvasko merged commit 409ee20 into CESNET:devel Nov 16, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants