[Bug]: default `parseHTML` is broken for some strings, because `fromString` is broken
Affected Packages
core
Version(s)
since 2.0.0 / since e07a5b6
Bug Description
default parseHTML for attributes uses fromString:
https://github.com/ueberdosis/tiptap/blob/next/packages/core/src/utilities/fromString.ts#L6
which treats any string of numbers as a Number, causing truncation, etc.
Reproduce:
- string like
"292050160422336065"set as an attribute is stored as number292050160422336060 - string like
"99999999999999999198731984792183719284731982749182498174981749287149281479284721984719847912847982174192873831293812739821397213987123987219387219387219387291837298139218392817397"is stored like number1e+179 - you get the idea
Browser Used
Firefox
Code Example URL
No response
Expected Behavior
The transformation should imho not be done if the representations are not completely equivalent. Assuming that string should be treated as Number is a bit of a stretch in itself, eating any string of numbers is incorrect.
Steps to fix:
Fixes:
A) only transform to number if the Number(value).toString() === value (possibly ignoring leading + sign).
B) split the regex into integer and floating point and check against MAX_SAFE_INTEGER etc., imho A) better.
Additional Context (Optional)
No response
Dependency Updates
- Yes, I've updated all my dependencies.
Source: ueberdosis/tiptap