Skip to content

Commit

Permalink
fix(core): Stringify all Luxon DateTimes in cleanupParameterData (#8959)
Browse files Browse the repository at this point in the history
  • Loading branch information
elsmr authored and krynble committed Mar 25, 2024
1 parent 1316f2d commit 58d9983
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/test/NodeExecuteFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 58d9983

Please sign in to comment.