Skip to content

Reject amount strings with trailing or invalid characters - #44

Open
Bornoz wants to merge 1 commit into
circlefin:masterfrom
Bornoz:fix/parseamount-reject-trailing-chars
Open

Reject amount strings with trailing or invalid characters#44
Bornoz wants to merge 1 commit into
circlefin:masterfrom
Bornoz:fix/parseamount-reject-trailing-chars

Conversation

@Bornoz

@Bornoz Bornoz commented Aug 31, 2026

Copy link
Copy Markdown

parseAmount stripped formatting characters and then called parseFloat, which parses a leading numeric prefix and ignores the rest. So malformed strings were silently accepted as different values:

input before after
10abc 10 rejected
1.25xyz 1.25 rejected
1e5 100000 rejected
10 10 10
$1,000.50 1000.5 1000.5

Since parseAmount feeds deposit and refund flows, silently recording a different amount is the wrong failure mode for monetary values. The cleaned string is now required to be a plain decimal in its entirety before parsing.

Closes #38

parseAmount stripped formatting characters and then called parseFloat, which parses a leading numeric prefix and ignores the rest. So "10abc" parsed as 10 and "1.25xyz" as 1.25 — a malformed string was silently accepted as a smaller-looking but different value. "1e5" parsed as 100000. For monetary values used in deposit and refund flows this is the wrong failure mode.

Require the cleaned string to be a plain decimal in its entirety before parsing, so anything with trailing or non-numeric characters is rejected instead. Valid formatted inputs like $1,000.50 still parse to 1000.5.

Closes circlefin#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