From 49d984a536824bd755a2eb4ab4a6edb6e38c45ab Mon Sep 17 00:00:00 2001 From: atakan g Date: Sun, 16 Aug 2026 01:21:39 +0300 Subject: [PATCH] fix: validate full amount string before parsing --- lib/utils/amount.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/utils/amount.ts b/lib/utils/amount.ts index 1571278..9c9cd78 100644 --- a/lib/utils/amount.ts +++ b/lib/utils/amount.ts @@ -22,10 +22,14 @@ export const parseAmount = (amountStr: string): number => { .replace(/[$€£,\s]/g, "") .replace(/−/g, "-"); - // Parse the amount - const amount = parseFloat(cleanAmount); + // Validate the entire normalized string before parsing + if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(cleanAmount)) { + throw new Error(`Invalid amount: ${amountStr}`); + } + + const amount = Number(cleanAmount); - if (Number.isNaN(amount) || amount <= 0) { + if (!Number.isFinite(amount) || amount <= 0) { throw new Error(`Invalid amount: ${amountStr}`); }