mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
deepCopy node execution data to prevent mutation
This commit is contained in:
parent
7e9d186496
commit
9ecf638251
|
@ -255,11 +255,11 @@ export class WorkflowDataProxy {
|
|||
shortSyntax?: boolean;
|
||||
}) {
|
||||
try {
|
||||
return this.getNodeExecutionData(nodeName, shortSyntax, branchIndex, runIndex);
|
||||
return deepCopy(this.getNodeExecutionData(nodeName, shortSyntax, branchIndex, runIndex));
|
||||
} catch (e) {
|
||||
const pinData = getPinDataIfManualExecution(this.workflow, nodeName, this.mode);
|
||||
if (pinData) {
|
||||
return pinData;
|
||||
return deepCopy(pinData);
|
||||
}
|
||||
|
||||
throw e;
|
||||
|
@ -412,7 +412,6 @@ export class WorkflowDataProxy {
|
|||
nodeName,
|
||||
shortSyntax,
|
||||
});
|
||||
|
||||
if (executionData.length === 0) {
|
||||
if (that.workflow.getParentNodes(nodeName).length === 0) {
|
||||
throw new ExpressionError('No execution data available', {
|
||||
|
@ -958,7 +957,7 @@ export class WorkflowDataProxy {
|
|||
});
|
||||
}
|
||||
|
||||
return taskData.data!.main[previousNodeOutput]![pairedItem.item];
|
||||
return deepCopy(taskData.data!.main[previousNodeOutput]![pairedItem.item]);
|
||||
};
|
||||
|
||||
const base = {
|
||||
|
@ -1228,7 +1227,7 @@ export class WorkflowDataProxy {
|
|||
return () => {
|
||||
const result = that.connectionInputData;
|
||||
if (result.length) {
|
||||
return result;
|
||||
return deepCopy(result);
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
|
|
@ -208,6 +208,20 @@ describe('WorkflowDataProxy', () => {
|
|||
name: 'test workflow',
|
||||
});
|
||||
});
|
||||
|
||||
test('should not be able to modify previous node data', () => {
|
||||
proxy.$json.data = 'updated!';
|
||||
expect(proxy.$json.data).toEqual(105);
|
||||
|
||||
proxy.$('Function').item.json.initialName = 'updated!';
|
||||
expect(proxy.$('Function').item.json.initialName).toEqual(105);
|
||||
|
||||
proxy.$input.all()[1].json.data = 'updated!';
|
||||
expect(proxy.$input.all()[1].json.data).toEqual(160);
|
||||
|
||||
proxy.$('Rename').first().json.data = 'updated!';
|
||||
expect(proxy.$('Rename').first().json.data).toEqual(105);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Errors', () => {
|
||||
|
|
Loading…
Reference in a new issue