Skip to content

fix: validate full amount string before parsing - #39

Open
AtakanGs wants to merge 1 commit into
circlefin:masterfrom
AtakanGs:fix/strict-amount-validation
Open

fix: validate full amount string before parsing#39
AtakanGs wants to merge 1 commit into
circlefin:masterfrom
AtakanGs:fix/strict-amount-validation

Conversation

@AtakanGs

Copy link
Copy Markdown

Summary

Fixes #38 by validating the entire normalized amount string before converting it to a number.

parseFloat() accepts a valid numeric prefix and ignores trailing invalid characters, so inputs such as 10abc or 1.25xyz were previously accepted as 10 and 1.25.

This change:

  • validates the complete normalized string with a decimal-number pattern
  • switches conversion from parseFloat() to Number() after validation
  • keeps the existing positive/finite amount check
  • preserves supported formatting normalization for currency symbols, commas, whitespace, parentheses, and Unicode minus

Behavior

Valid examples continue to work:

  • $1,234.561234.56
  • 1,234.561234.56
  • 1.251.25
  • .50.5

Malformed values are now rejected:

  • 10abc
  • 1.25xyz
  • 5USDCx

Testing

The repository does not currently include a test script/framework for this utility, so I verified the parsing behavior directly with Node and also ran git diff --check successfully.

Closes #38.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: parseAmount accepts malformed amount strings with trailing characters

1 participant