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}`); }