Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-5648

Add a Long.validateString method that constrains string input to only valid characters

    XMLWordPrintableJSON

Details

    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

    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

        Activity

          People

            Unassigned Unassigned
            neal.beeken@mongodb.com Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: