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;
|
shortSyntax?: boolean;
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
return this.getNodeExecutionData(nodeName, shortSyntax, branchIndex, runIndex);
|
return deepCopy(this.getNodeExecutionData(nodeName, shortSyntax, branchIndex, runIndex));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const pinData = getPinDataIfManualExecution(this.workflow, nodeName, this.mode);
|
const pinData = getPinDataIfManualExecution(this.workflow, nodeName, this.mode);
|
||||||
if (pinData) {
|
if (pinData) {
|
||||||
return pinData;
|
return deepCopy(pinData);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -412,7 +412,6 @@ export class WorkflowDataProxy {
|
||||||
nodeName,
|
nodeName,
|
||||||
shortSyntax,
|
shortSyntax,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (executionData.length === 0) {
|
if (executionData.length === 0) {
|
||||||
if (that.workflow.getParentNodes(nodeName).length === 0) {
|
if (that.workflow.getParentNodes(nodeName).length === 0) {
|
||||||
throw new ExpressionError('No execution data available', {
|
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 = {
|
const base = {
|
||||||
|
@ -1228,7 +1227,7 @@ export class WorkflowDataProxy {
|
||||||
return () => {
|
return () => {
|
||||||
const result = that.connectionInputData;
|
const result = that.connectionInputData;
|
||||||
if (result.length) {
|
if (result.length) {
|
||||||
return result;
|
return deepCopy(result);
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
|
|
|
@ -208,6 +208,20 @@ describe('WorkflowDataProxy', () => {
|
||||||
name: 'test workflow',
|
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', () => {
|
describe('Errors', () => {
|
||||||
|
|
Loading…
Reference in a new issue