fix(utils): handle string scientific notation in parseUnits - #1990
Closed
Lesnak1 wants to merge 1 commit into
Closed
fix(utils): handle string scientific notation in parseUnits#1990Lesnak1 wants to merge 1 commit into
Lesnak1 wants to merge 1 commit into
Conversation
Collaborator
|
Thanks for this! We recreated the fix in our internal monorepo, with you credited as co-author on the commit: This repo is a read-only mirror, so we can't merge PRs here directly, but we read every one. This will ship in the next |
Author
|
Thanks @ryanio ! Glad to help make |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a
SyntaxErrorinparseUnitswhen passing a string formatted in scientific notation (e.g."1e-8","1.5e-5","1E-6").Previously, the scientific notation check checked
typeof value === "number" && str.includes("e"). Whenvaluewas passed as a string containing exponential notation ("1e-8"), the condition evaluated tofalse, leavingstras"1e-8". During unit calculation, this produced"1e-8000000000000000000", causingBigInt(...)to throwSyntaxError: Cannot convert 1e-8000000000000000000 to a BigInt.Changes
parseUnitsinsrc/utils/units.tsto checkstr.toLowerCase().includes("e")regardless of whethervaluewas passed as anumberorstring.test/utils/units.spec.ts.Testing
handles string scientific notationfailed onmainwithSyntaxError.npm test).