Skip to content

Commit 80a8094

Browse files
authored
fix(util-dynamodb): unmarshall small numbers or those in scientific notation (#2017)
1 parent 569b572 commit 80a8094

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

Diff for: packages/util-dynamodb/src/convertToNative.spec.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,15 @@ describe("convertToNative", () => {
7272
});
7373
});
7474

75-
[
76-
`${Number.MAX_SAFE_INTEGER}.1`,
77-
`${Number.MIN_SAFE_INTEGER}.1`,
78-
`${Number.MIN_VALUE}1`,
79-
`-${Number.MIN_VALUE}1`,
80-
].forEach((numString) => {
81-
it(`throws if number is outside IEEE 754 Floating-Point Arithmetic: ${numString}`, () => {
82-
expect(() => {
83-
convertToNative({ N: numString });
84-
}).toThrowError(
85-
`Value ${numString} is outside IEEE 754 Floating-Point Arithmetic. Set options.wrapNumbers to get string value.`
86-
);
75+
[`0.0000001`, `0.0000000001`, `0.00000000000000000001`].forEach((numString) => {
76+
it(`returns for small numbers: ${numString}`, () => {
77+
expect(convertToNative({ N: numString })).toEqual(Number(numString));
78+
});
79+
});
80+
81+
[`1e-7`, `1e-20`, `1e15`].forEach((numString) => {
82+
it(`returns numbers stored in scientific notation: ${numString}`, () => {
83+
expect(convertToNative({ N: numString })).toEqual(Number(numString));
8784
});
8885
});
8986

Diff for: packages/util-dynamodb/src/convertToNative.ts

-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ const convertNumber = (numString: string, options?: unmarshallOptions): number |
5858
} else {
5959
throw new Error(`${numString} is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.`);
6060
}
61-
} else if (num.toString() !== numString) {
62-
throw new Error(
63-
`Value ${numString} is outside IEEE 754 Floating-Point Arithmetic. Set options.wrapNumbers to get string value.`
64-
);
6561
}
6662
return num;
6763
};

0 commit comments

Comments
 (0)