Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(util-dynamodb): unmarshall small numbers or those in scientific notation #2017

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions packages/util-dynamodb/src/convertToNative.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,15 @@ describe("convertToNative", () => {
});
});

[
`${Number.MAX_SAFE_INTEGER}.1`,
`${Number.MIN_SAFE_INTEGER}.1`,
`${Number.MIN_VALUE}1`,
`-${Number.MIN_VALUE}1`,
].forEach((numString) => {
it(`throws if number is outside IEEE 754 Floating-Point Arithmetic: ${numString}`, () => {
expect(() => {
convertToNative({ N: numString });
}).toThrowError(
`Value ${numString} is outside IEEE 754 Floating-Point Arithmetic. Set options.wrapNumbers to get string value.`
);
[`0.0000001`, `0.0000000001`, `0.00000000000000000001`].forEach((numString) => {
it(`returns for small numbers: ${numString}`, () => {
expect(convertToNative({ N: numString })).toEqual(Number(numString));
});
});

[`1e-7`, `1e-20`, `1e15`].forEach((numString) => {
it(`returns numbers stored in scientific notation: ${numString}`, () => {
expect(convertToNative({ N: numString })).toEqual(Number(numString));
});
});

Expand Down
4 changes: 0 additions & 4 deletions packages/util-dynamodb/src/convertToNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ const convertNumber = (numString: string, options?: unmarshallOptions): number |
} else {
throw new Error(`${numString} is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.`);
}
} else if (num.toString() !== numString) {
throw new Error(
`Value ${numString} is outside IEEE 754 Floating-Point Arithmetic. Set options.wrapNumbers to get string value.`
);
}
return num;
};
Expand Down