Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/long.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,11 @@ export class Long extends BSONValue {
unsigned = !!unsignedOrRadix;
}
radix ??= 10;
if (str === 'NaN' || str === 'Infinity' || str === '+Infinity' || str === '-Infinity') {
if (str === 'NaN' && radix < 24) {
// radix does not support n, so coerce to zero
return Long.ZERO;
} else if ((str === 'Infinity' || str === '+Infinity' || str === '-Infinity') && radix < 35) {
// radix does not support y, so coerce to zero
return Long.ZERO;
}
return Long._fromString(str, unsigned, radix);
Expand Down
12 changes: 8 additions & 4 deletions test/node/long.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,14 @@ describe('Long', function () {
radix: number | undefined,
expectedStr?: string
][] = [
['Infinity', 'Infinity', false, 34, '0'],
['-Infinity', '-Infinity', false, 23, '0'],
['+Infinity', '+Infinity', false, 12, '0'],
['NaN', 'NaN', false, 16, '0']
['radix 36 Infinity', 'Infinity', false, 36],
['radix 36 -Infinity', '-Infinity', false, 36],
['radix 36 +Infinity', '+Infinity', false, 36, 'infinity'],
['radix < 35 Infinity', 'Infinity', false, 34, '0'],
['radix < 35 -Infinity', '-Infinity', false, 23, '0'],
['radix < 35 +Infinity', '+Infinity', false, 12, '0'],
['radix < 24 NaN', 'NaN', false, 16, '0'],
['radix > 24 NaN', 'NaN', false, 25]
];

for (const [testName, str, unsigned, radix, expectedStr] of successInputs) {
Expand Down