From dae054fd6b58e673b7814271acc01ceced983cac Mon Sep 17 00:00:00 2001 From: DavidGracias Date: Fri, 5 Sep 2025 17:33:29 -0400 Subject: [PATCH] fix(core/formatters): ensure null values trigger the false check case in conditional modifiers (#348) Co-authored-by: David Garcia --- packages/core/src/formatters/base.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/core/src/formatters/base.ts b/packages/core/src/formatters/base.ts index 49b5db04..39c40603 100644 --- a/packages/core/src/formatters/base.ts +++ b/packages/core/src/formatters/base.ts @@ -211,7 +211,7 @@ export const conditionalModifiers = { 'exists': (value: any) => { // Handle null, undefined, empty strings, empty arrays if (value === undefined || value === null) return false; - if (typeof value === 'string') return (value.trim().length > 0 && value != 'null' && value != 'undefined'); + if (typeof value === 'string') return (value.replace(/ /g, '').length > 0); if (Array.isArray(value)) return value.length > 0; // For other types (numbers, booleans, objects), consider them as "existing" return true; @@ -539,7 +539,14 @@ export abstract class BaseFormatter { // try to coerce true/false value from modifier let conditional: boolean | undefined; try { - if (isExact) { + + // PRE-CHECK(s) -- skip resolving conditional modifier if value DNE, defaulting to false conditional + if (!conditionalModifiers.exact.exists(value)) { + conditional = false; + } + + // EXACT + else if (isExact) { const modAsKey = mod as keyof typeof conditionalModifiers.exact; conditional = conditionalModifiers.exact[modAsKey](value); }