-
Type: Sub-task
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
Currently, users can pass in invalid input into Double constructor, and the inputs will be coerced to a value regardless of if the input is valid.
This subtask will create a Double.fromString helper that will validate input for these classes and throw on inputs that are not representable as a Double.
In V7, we will add these helpers to the Double constructor when a string input is passed in, so the numeric conversion will only happen after validation.
Use Case
As a... BSON Double Class user
I want... my string inputs to throw when they will lose precision
So that... the value stored in the Double instance is the desired value
Acceptance Criteria
Implementation Requirements
- General Approach
- Remove leading zeros in comparison
- Don't allow whitespace (decimal 128 precedent)
- Only allow decimal input
- Error Cases
- Don't allow non-decimal inputs (if string contains, a 'x' 'c' 'b')
- Empty string
- Number(value) === NaN but value is not 'NaN'
- (something other than a NaN is coerced to a NaN)
- !Number.isFinite(+value) but value is not 'Infinity' or '-Infinity'
- If not error case, return Number(value)
Testing Requirements
- Double Cases
- Success Cases:
- 'NaN', 'Infinity', '-Infinity', 0, -0
- Fraction
- Basic test case for decimal
- whitespace leading, trailing
- leading zeros
- Error Cases:
- 'foo'
- ex: '2e308' (coerced to Infinity by Number(), but is not actually infinity'
- Non-decimal inputs
- Success Cases:
Documentation Requirements
- add API docs for Double.fromString
Follow Up Requirements
- file v7 ticket (in subtasks)