mirror of https://github.com/node-red/node-red.git
Merge pull request #4654 from node-red/fix-subflow-recursion-check
Prevent subflow being added to itselfpull/4655/head
commit
7ac7f9b4c8
|
@ -646,6 +646,7 @@ RED.view = (function() {
|
|||
}
|
||||
d3.event = event;
|
||||
var selected_tool = $(ui.draggable[0]).attr("data-palette-type");
|
||||
try {
|
||||
var result = createNode(selected_tool);
|
||||
if (!result) {
|
||||
return;
|
||||
|
@ -761,6 +762,13 @@ RED.view = (function() {
|
|||
if (nn._def.autoedit) {
|
||||
RED.editor.edit(nn);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.code != "NODE_RED") {
|
||||
RED.notify(RED._("notification.error",{message:error.toString()}),"error");
|
||||
} else {
|
||||
RED.notify(RED._("notification.error",{message:error.message}),"error");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
chart.on("focus", function() {
|
||||
|
@ -6063,14 +6071,19 @@ RED.view = (function() {
|
|||
function createNode(type, x, y, z) {
|
||||
const wasDirty = RED.nodes.dirty()
|
||||
var m = /^subflow:(.+)$/.exec(type);
|
||||
var activeSubflow = z ? RED.nodes.subflow(z) : null;
|
||||
var activeSubflow = (z || RED.workspaces.active()) ? RED.nodes.subflow(z || RED.workspaces.active()) : null;
|
||||
|
||||
if (activeSubflow && m) {
|
||||
var subflowId = m[1];
|
||||
let err
|
||||
if (subflowId === activeSubflow.id) {
|
||||
throw new Error(RED._("notification.error", { message: RED._("notification.errors.cannotAddSubflowToItself") }))
|
||||
err = new Error(RED._("notification.errors.cannotAddSubflowToItself"))
|
||||
} else if (RED.nodes.subflowContains(m[1], activeSubflow.id)) {
|
||||
err = new Error(RED._("notification.errors.cannotAddCircularReference"))
|
||||
}
|
||||
if (RED.nodes.subflowContains(m[1], activeSubflow.id)) {
|
||||
throw new Error(RED._("notification.error", { message: RED._("notification.errors.cannotAddCircularReference") }))
|
||||
if (err) {
|
||||
err.code = 'NODE_RED'
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue