-
Notifications
You must be signed in to change notification settings - Fork 252
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
feat(NODE-5648): add Long.fromStringStrict() #675
Conversation
68d736d
to
c4818d9
Compare
…cit overloads with different docs
src/long.ts
Outdated
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we checking the radix here? This changes the behavior of Long.fromString - something we want to avoid in this PR. The logic was previously:
if (str === 'NaN' || str === 'Infinity' || str === '+Infinity' || str === '-Infinity')
return Long.ZERO;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does change the behavior of Long.fromString
, but its another bug fix, (see updated release notes).
We previously did not allow valid inputs to radices, because we interpreted them as 'not a number,' but in radix >= 24
, 'nan' is a valid number (since 'n' and 'a' are in the character set for numbers).
Example:
Long.fromString('NaN', 27); // new Long(17060)
The original Long.fromString
would return Long.ZERO
on '+/- Infinity' and 'NaN' cases, and then check for radix later. This behavior is still preserved, other than in the case that the user is not actually inputting 'not a number' or an infinite value, but a valid non-infinite Long written in a high radix.
Description
Add
Long.fromStringStrict
which throws an error if the input string has invalid characters.What is changing?
See above.
Is there new documentation needed for these changes?
Yes, we should request docs changes, and there is an API docs addition.
What is the motivation for this change?
User submitted bug: NODE-5638.
Release Highlight
Add
Long.fromStringStrict
methodThe
Long.fromStringStrict
method is almost identical to theLong.fromString
method, except it throws aBSONError
if any of the following are true:Unlike
Long.fromString
, this method does not coerce the inputs'+/-Infinity'
and'NaN'
toLong.ZERO
, in any case.Examples:
Note
Long.fromStringStrict
's functionality will be present inLong.fromString
in the V7 BSON release.Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript