fix: reject malformed amount strings in validateStringAmount#348
Open
Snowmanzx wants to merge 1 commit into
Open
fix: reject malformed amount strings in validateStringAmount#348Snowmanzx wants to merge 1 commit into
Snowmanzx wants to merge 1 commit into
Conversation
validateStringAmount used parseFloat, which reads a leading numeric prefix so values like "1abc", "1.2.3" and "1e6" passed validation and only failed later in parseUnits. Replaced it with a strict decimal check. Negative and zero amounts still report must be greater than 0 as before, so existing tests keep passing.
Collaborator
🟡 Heimdall Review Status
|
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.
validateStringAmount used parseFloat to check the amount. parseFloat reads a leading numeric prefix and ignores the rest, so "1abc" becomes 1, "1.2.3" becomes 1.2 and "1e6" becomes 1000000. Those pass validation and only fail later in parseUnits, which expects a plain decimal string. A commenter on the issue also flagged the "1e6" scientific notation case.
Replaced the parseFloat check with a strict decimal regex. The rest of the behavior is unchanged on purpose: negative and zero amounts still throw "must be greater than 0", non string input still throws "must be a string", and the max decimal places check is untouched. All existing tests still pass.
Added a test that runs the malformed inputs through the validator and checks they are rejected.
Closes #313