• Type: Icon: Sub-task Sub-task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • bson-6.7.0
    • Affects Version/s: None
    • Component/s: None
    • 0
    • Not Needed
    • Hide

      Create a copy of the Kickoff Template with the issue key (NODE-XXX) in the filename and share a link to the new doc via this field.

      Show
      Create a copy of the Kickoff Template with the issue key (NODE-XXX) in the filename and share a link to the new doc via this field.
    • 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?

      Currently, users can pass in invalid input into Int32 constructor, and the inputs will be coerced to a value regardless of if the input is valid.

      This subtask will create a Int32.fromString helper that will validate input for these class and throw on inputs that are not representable as Int32.

      In V7, we will add this helper to the Int32 constructor when a string input is passed in, so the numeric conversion will only happen after validation.

       

      Note: I am using the Number() string conversion docs to guide my implementation. 

      Use Case

      As a... BSON user 
      I want... correct validation for when I create a int32 from a string
      So that... the value in BSON matches what is actually passed in 

      User Impact

      • Some, but will impact more in v7 follow-up

      Dependencies

      • none, this is a new feature

      Acceptance Criteria

      Implementation Requirements

      • Int32.fromString(string:value): number  
        • General Approach
          • whitespace is NOT allowed
          • leading zeros are allowed
          • only decimal notation is allowed
        • Error Cases
          • return Number(value).toString() !== value
          • returns a NaN on Number(value)
          • !Number.isSafeInteger
            • bounds check with int32.max and min
            • checks if fractional
          • -0
          • empty string
          • No leading or trailing whitespace allowed
        • If not error:  return Number(value)

      Testing Requirements

      • Int32 Cases
        • Success Cases:
          • Max and Min: int32.max, int32.min 
          • 0
          • default / basic case for decimal case
        • Error Cases:
          • Out of bounds: int32.max+1, int32.min - 1
          • '-Infinity', '+Infinity'
          • 'NaN'
          • fraction
          • -0
          • non-decimal cases

      Documentation Requirements

      • add API docs for Int32.fromString

      Follow Up Requirements

      • file v7 ticket (in subtasks)

            Assignee:
            aditi.khare@mongodb.com Aditi Khare
            Reporter:
            aditi.khare@mongodb.com Aditi Khare
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: