From 7dc24f14ed421bc21ae1ca8e2f98b7e5b4c946a5 Mon Sep 17 00:00:00 2001 From: omar abdelzaher sleam Date: Tue, 4 Apr 2023 17:20:09 +0000 Subject: [PATCH 1/3] try solve the numbers equations --- src/litegraph.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/litegraph.js b/src/litegraph.js index bc1a34e86..b90de11ed 100644 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -9985,6 +9985,10 @@ LGraphNode.prototype.executeAction = function(action) var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0; if (event.click_time < 200 && delta == 0) { this.prompt("Value",w.value,function(v) { + try {//solve the equation if possible + v = eval(v); + } catch (error) { + } this.value = Number(v); inner_value_change(this, this.value); }.bind(w), From b0f0eb9ea991f4191d783430da5047f925a945cd Mon Sep 17 00:00:00 2001 From: omar abdelzaher sleam Date: Wed, 5 Apr 2023 05:19:33 +0200 Subject: [PATCH 2/3] secure eval --- src/litegraph.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/litegraph.js b/src/litegraph.js index b90de11ed..d6eb00a2d 100644 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -9985,10 +9985,13 @@ LGraphNode.prototype.executeAction = function(action) var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0; if (event.click_time < 200 && delta == 0) { this.prompt("Value",w.value,function(v) { - try {//solve the equation if possible - v = eval(v); - } catch (error) { - } + this.prompt("Value",w.value,function(v) { + // check if v is a valid equation or a number + if (/^[0-9+\-*/()\s]+$/.test(v)) { + try {//solve the equation if possible + v = eval(v); + } catch (e) { } + } this.value = Number(v); inner_value_change(this, this.value); }.bind(w), From 2a7f8d4fff04f2458a3c5a8b8b7f36ae3b06601a Mon Sep 17 00:00:00 2001 From: omar abdelzaher sleam Date: Wed, 5 Apr 2023 05:20:29 +0200 Subject: [PATCH 3/3] remove duplicated line --- src/litegraph.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/litegraph.js b/src/litegraph.js index d6eb00a2d..2f2d6ef71 100644 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -9984,7 +9984,6 @@ LGraphNode.prototype.executeAction = function(action) { var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0; if (event.click_time < 200 && delta == 0) { - this.prompt("Value",w.value,function(v) { this.prompt("Value",w.value,function(v) { // check if v is a valid equation or a number if (/^[0-9+\-*/()\s]+$/.test(v)) {