Skip to content

fix(core/protocols): handle JSON exponent notation in jsonReviver#8226

Merged
kuhe merged 1 commit into
mainfrom
kuhe/fix/numeric
Jul 24, 2026
Merged

fix(core/protocols): handle JSON exponent notation in jsonReviver#8226
kuhe merged 1 commit into
mainfrom
kuhe/fix/numeric

Conversation

@kuhe

@kuhe kuhe commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Related to #8224, see also smithy-lang/smithy-typescript#2184

The jsonReviver incorrectly classified exponent-notation numbers (e.g. 1.784316439424E9) as precision-losing, because numericString !== String(value) always fails when the source uses exponent notation.

@kuhe
kuhe requested a review from a team as a code owner July 24, 2026 22:29
@kuhe
kuhe force-pushed the kuhe/fix/numeric branch 4 times, most recently from e0c3e12 to c20dd4f Compare July 24, 2026 22:49
The reviver incorrectly classified exponent-notation numbers (e.g.
1.784316439424E9) as precision-losing because numericString !== String(value)
always fails for alternate notations. This caused deserialization failures
for any awsJson response containing exponent-notation numbers, which AWS
services emit for epoch-second timestamps (e.g. ECS createdAt).

Fix: when the source contains exponent notation ([eE]) and the value is
within safe integer bounds, normalize via String(Number(source)) and compare
against String(value). If they match, the number round-trips exactly and is
returned as a plain JS number.

For values outside safe integer bounds with exponent notation:
- Fractional (e.g. 1.23E100) → NumericValue (requires smithy-lang/smithy-typescript#2184)
- Non-fractional (e.g. 1E19) → BigInt via Number() conversion

Also fixes BigInt path to handle exponent notation (BigInt() doesn't accept
'1E19' directly, so we normalize through Number() first).

Fixes: #8224
@kuhe
kuhe force-pushed the kuhe/fix/numeric branch from c20dd4f to 16d8650 Compare July 24, 2026 22:52
@kuhe kuhe changed the title fix(protocols): handle JSON exponent notation in jsonReviver fix(core/protocols): handle JSON exponent notation in jsonReviver Jul 24, 2026
@kuhe
kuhe merged commit c3b27fd into main Jul 24, 2026
7 checks passed
@kuhe
kuhe deleted the kuhe/fix/numeric branch July 24, 2026 23:34
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