From c3ceaab9675de1b27d18b5f54f5f3eb2a8675e3a Mon Sep 17 00:00:00 2001 From: Priya Raman Date: Wed, 11 Mar 2026 15:47:02 +0000 Subject: Re: [PATCH] fix(format): reject amounts with no digits On Wed, 11 Mar 2026, Miguel Otero wrote: > Could you resend with the NaN guard folded in? Sure — updated version below. -- >8 -- fix(format): reject amounts with no digits parseMinor returned NaN for input with no digits at all, and the caller stored it as zero. --- 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