Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: reject boolean and blank-string weights that coerce to zero (#3794)

[._.]/ Adam Eivyfda959497e63
diff --git a/client/src/utils/formatters.js b/client/src/utils/formatters.js
index 54b223ff71..5820ab38b2 100644
--- a/client/src/utils/formatters.js
+++ b/client/src/utils/formatters.js
@@ -144,9 +144,12 @@ export function formatCompactCount(n) {
* @returns {number|null}
*/
function roundForDisplay(value, decimals) {
- // `Number(null)` and `Number('')` are both 0, which would render a missing
- // measurement as a real "0 lbs" — reject the absent cases before coercing.
- if (value === null || value === undefined || value === '') return null;
+ // `Number(null)`, `Number('')`, `Number(' ')` and `Number(false)` are all 0,
+ // which would render a missing measurement as a real "0 lbs" — accept only a
+ // number or a non-blank numeric string before coercing.
+ const isNumeric = typeof value === 'number'
+ || (typeof value === 'string' && value.trim() !== '');
+ if (!isNumeric) return null;
const n = Number(value);
if (!Number.isFinite(n)) return null;
return parseFloat(n.toFixed(decimals));
diff --git a/client/src/utils/formatters.test.js b/client/src/utils/formatters.test.js
index 1d24dffc37..3fcba0798f 100644
--- a/client/src/utils/formatters.test.js
+++ b/client/src/utils/formatters.test.js
@@ -30,6 +30,10 @@ describe('formatWeight', () => {
expect(formatWeight(NaN)).toBe('—');
expect(formatWeight(Infinity)).toBe('—');
expect(formatWeight(null, { fallback: 'n/a' })).toBe('n/a');
+ // Values that coerce to 0 must not render as a real measurement.
+ expect(formatWeight(' ')).toBe('—');
+ expect(formatWeight(false)).toBe('—');
+ expect(formatWeight([])).toBe('—');
});
it('keeps a legitimate zero rather than treating it as missing', () => {