From b25931ed0e9953d98861ca1c8d7fb4ae3ba27358 Mon Sep 17 00:00:00 2001 From: Ada Fernsby Date: Mon, 9 Mar 2026 07:45:19 +0000 Subject: [PATCH] fix(format): reject amounts with no digits parseMinor returned NaN, which reached the database as 0. --- web/src/format.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/src/format.ts b/web/src/format.ts index fd6b21b..5d40a9f 100644 --- a/web/src/format.ts +++ b/web/src/format.ts @@ -1,9 +1,11 @@ export interface Money { amount: number; currency: string; + locale?: string; } const GROUPING = 3; +const DEFAULT_LOCALE = "en-GB"; export function formatMinor(minor: number, currency: string): string { const sign = minor < 0 ? "-" : ""; @@ -33,5 +35,9 @@ export function parseMinor(text: string): number { const cleaned = text.replace(/[^0-9-]/g, ""); - return Number.parseInt(cleaned, 10); + const parsed = Number.parseInt(cleaned, 10); + if (Number.isNaN(parsed)) { + throw new RangeError("parseMinor: no digits in " + JSON.stringify(text)); + } + return parsed; } -- 2.43.0