mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-12 02:19:43 +00:00
fix(core): Preserve Date values passed to the expression isolate (#33322)
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
723749c18d
commit
9410e961b9
@@ -284,6 +284,34 @@ describe('Integration: ExpressionEvaluator + IsolatedVmBridge', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Date marshaling from workflow data', () => {
|
||||
it('should read a top-level Date in $json as a Date, not {}', () => {
|
||||
const data = { $json: { d: new Date('2026-06-30T20:34:04.498Z') } };
|
||||
|
||||
const result = evaluator.evaluate('{{ $json.d }}', data, caller);
|
||||
|
||||
expect(result).not.toEqual({});
|
||||
expect(result).toBeInstanceOf(Date);
|
||||
expect((result as Date).toISOString()).toBe('2026-06-30T20:34:04.498Z');
|
||||
});
|
||||
|
||||
it('should read a nested Date in $json (e.g. Data Table createdAt)', () => {
|
||||
const data = { $json: { row: { createdAt: new Date('2026-06-30T20:34:04.498Z') } } };
|
||||
|
||||
const result = evaluator.evaluate('{{ $json.row.createdAt }}', data, caller);
|
||||
|
||||
expect(result).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
it('should read a Date array element in $json', () => {
|
||||
const data = { $json: { dates: [new Date('2026-06-30T20:34:04.498Z')] } };
|
||||
|
||||
const result = evaluator.evaluate('{{ $json.dates[0] }}', data, caller);
|
||||
|
||||
expect(result).toBeInstanceOf(Date);
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw on invalid timezone', async () => {
|
||||
const data = { $json: { x: 1 } };
|
||||
|
||||
|
||||
@@ -338,6 +338,12 @@ export class IsolatedVmBridge implements RuntimeBridge {
|
||||
};
|
||||
}
|
||||
|
||||
// Dates have no enumerable own keys; pass through instead of
|
||||
// marshaling as an empty object.
|
||||
if (value instanceof Date) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Handle objects - return metadata with keys
|
||||
if (value !== null && typeof value === 'object') {
|
||||
return {
|
||||
@@ -396,6 +402,12 @@ export class IsolatedVmBridge implements RuntimeBridge {
|
||||
|
||||
const element = arr[index];
|
||||
|
||||
// Dates have no enumerable own keys; pass through instead of
|
||||
// marshaling as an empty object.
|
||||
if (element instanceof Date) {
|
||||
return element;
|
||||
}
|
||||
|
||||
// If element is object/array, return metadata
|
||||
if (element !== null && typeof element === 'object') {
|
||||
if (Array.isArray(element)) {
|
||||
|
||||
Reference in New Issue
Block a user