From 9cc2671dcb2e640005042a865ef5b37c3f1a9424 Mon Sep 17 00:00:00 2001 From: Sander Toonen Date: Tue, 20 Jan 2026 15:11:41 +0100 Subject: [PATCH] Handle null in isEmpty and treat it as empty --- src/functions/string/operations.ts | 8 ++++++-- test/functions/functions-string.ts | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/functions/string/operations.ts b/src/functions/string/operations.ts index 533328c..59b9a26 100644 --- a/src/functions/string/operations.ts +++ b/src/functions/string/operations.ts @@ -17,15 +17,19 @@ export function stringLength(str: string | undefined): number | undefined { } /** - * Checks if a string is empty (length === 0) + * Checks if a string is empty (null or length === 0) */ -export function isEmpty(str: string | undefined): boolean | undefined { +export function isEmpty(str: string | null | undefined): boolean | undefined { if (str === undefined) { return undefined; + } + if (str === null) { + return true; } if (typeof str !== 'string') { throw new Error('Argument to isEmpty must be a string'); } + return str.length === 0; } diff --git a/test/functions/functions-string.ts b/test/functions/functions-string.ts index d975a6e..19f8769 100644 --- a/test/functions/functions-string.ts +++ b/test/functions/functions-string.ts @@ -25,6 +25,11 @@ describe('String Functions TypeScript Test', function () { assert.strictEqual(parser.evaluate('isEmpty("")'), true); }); + it('should return true for null values', function () { + const parser = new Parser(); + assert.strictEqual(parser.evaluate('isEmpty(null)'), true); + }); + it('should return false for non-empty strings', function () { const parser = new Parser(); assert.strictEqual(parser.evaluate('isEmpty("hello")'), false);