From fd337a4e7ac73ad1df7c0938ef234318252e5d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 10 Sep 2026 03:25:16 +0200 Subject: [PATCH] fix(import): match the molar-mass annotation by the shape Apple writes The catch-all angle-bracket pattern read as an HTML sanitiser to static analysis. The annotation Apple writes is a number, so the pattern now matches exactly that, and a unit with anything else between the brackets stays unknown instead of being silently trimmed into a lookup. --- src/lib/measurements/__tests__/hk-units.test.ts | 2 ++ src/lib/measurements/hk-units.ts | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/measurements/__tests__/hk-units.test.ts b/src/lib/measurements/__tests__/hk-units.test.ts index b1162fb6b..d03b77939 100644 --- a/src/lib/measurements/__tests__/hk-units.test.ts +++ b/src/lib/measurements/__tests__/hk-units.test.ts @@ -30,6 +30,8 @@ describe("convertHkValue", () => { 99.0858, 4, ); + expect(isConvertibleHkUnit("mmol<180>/L")).toBe(true); + expect(isConvertibleHkUnit("mmol/L")).toBe(false); }); it("keeps the small calorie apart from the large one", () => { diff --git a/src/lib/measurements/hk-units.ts b/src/lib/measurements/hk-units.ts index f500be22d..1b5201b4c 100644 --- a/src/lib/measurements/hk-units.ts +++ b/src/lib/measurements/hk-units.ts @@ -120,10 +120,12 @@ const HK_UNITS: Record = { /** * Apple writes molar units with the substance's molar mass inline — - * `mmol<180.156>/L` for blood glucose. The annotation is informational; - * strip it so the lookup sees the plain unit. + * `mmol<180.156>/L` for blood glucose. The annotation is a number and + * informational; strip exactly that shape so the lookup sees the plain + * unit. Anything else between angle brackets is not a unit Apple writes + * and stays unknown. */ -const MOLAR_MASS_ANNOTATION = /<[^>]*>/g; +const MOLAR_MASS_ANNOTATION = /<\d+(?:\.\d+)?>/g; function normaliseUnitString(unit: string): string { return unit.trim().replace(MOLAR_MASS_ANNOTATION, "");