From 58d9983d0efd50d01d8406b949a4e7a3db63e465 Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Mon, 25 Mar 2024 09:44:10 +0100 Subject: [PATCH] fix(core): Stringify all Luxon DateTimes in cleanupParameterData (#8959) --- packages/core/src/NodeExecuteFunctions.ts | 2 +- packages/core/test/NodeExecuteFunctions.test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index ca1ea6028bae3..cecabed23957a 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -2112,7 +2112,7 @@ export function cleanupParameterData(inputData: NodeParameterValueType): void { (Object.keys(inputData) as Key[]).forEach((key) => { const value = inputData[key]; if (typeof value === 'object') { - if (value instanceof DateTime) { + if (DateTime.isDateTime(value)) { // Is a special luxon date so convert to string inputData[key] = value.toString(); } else { diff --git a/packages/core/test/NodeExecuteFunctions.test.ts b/packages/core/test/NodeExecuteFunctions.test.ts index a644cd6793ec5..92f23782189d4 100644 --- a/packages/core/test/NodeExecuteFunctions.test.ts +++ b/packages/core/test/NodeExecuteFunctions.test.ts @@ -30,6 +30,7 @@ import { tmpdir } from 'os'; import { join } from 'path'; import Container from 'typedi'; import type { Agent } from 'https'; +import toPlainObject from 'lodash/toPlainObject'; const temporaryDir = mkdtempSync(join(tmpdir(), 'n8n')); @@ -425,6 +426,16 @@ describe('NodeExecuteFunctions', () => { expect(typeof input.y).toBe('string'); }); + it('should stringify plain Luxon dates in-place', () => { + const input = { + x: 1, + y: toPlainObject(DateTime.now()), + }; + expect(typeof input.y).toBe('object'); + cleanupParameterData(input); + expect(typeof input.y).toBe('string'); + }); + it('should handle objects with nameless constructors', () => { const input = { x: 1, y: { constructor: {} } as NodeParameterValue }; expect(typeof input.y).toBe('object');