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, "");