Details
-
New Feature
-
Resolution: Unresolved
-
Major - P3
-
None
-
None
Description
Use Case
As a BSON and driver user
I want to ensure strings that represent longs only contain valid digits
So that int64s are constructed from proper digit sequences
User Impact
- New opt-in feature API
Dependencies
- None
Unknowns
- How to best validate radix inputs other than 10
- Can we optimize the radix 10 case using JS number APIs rather than regex?
- Consider: A base 10 string can be no longer than 20 digits and Number.isInteger(Number('9'.repeat(20))) // true
Acceptance Criteria
Implementation Requirements
- Add a new static method to the Long class validateString that throws when the input contains invalid characters.
- Long.validateString(input: string, radix?: [2, 36]): string
- The method must support radixes from 2 through 36 inclusive
- radix is an optional parameter that must default to 10
- The method will return the string if it is valid and throw an error if it is not.
Testing Requirements
- Test valid and invalid inputs
- Ensure usage: Long.fromString{Long.validateString(input, radix), radix) works
- Check radix optionality and defaulting behavior
- Check inputs for each radix in and out of bounds
Documentation Requirements
- Put API docs on Long.validateString with example usage
- Update Long.fromString API docs to mention Long.validateString
Follow Up Requirements
- In v7 (next BSON major) NODE-5638 Long.validateString will be called inside Long.fromString
Attachments
Issue Links
- related to
-
NODE-5638 Bizarre behavior on invalid strings in Long.fromString
-
- Backlog
-