Browse Source

fix_bug_switch: add validation to tbel

pull/8733/head
nickAS21 3 years ago
parent
commit
a85d0b6129
  1. 6
      common/script/script-api/src/main/java/org/thingsboard/script/api/tbel/DefaultTbelInvokeService.java
  2. 10
      ui-ngx/src/app/shared/models/ace/tbel/worker-tbel.js

6
common/script/script-api/src/main/java/org/thingsboard/script/api/tbel/DefaultTbelInvokeService.java

@ -25,6 +25,7 @@ import com.google.common.util.concurrent.MoreExecutors;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.mvel2.CompileException;
import org.mvel2.ExecutionContext;
import org.mvel2.MVEL;
import org.mvel2.ParserContext;
@ -65,6 +66,8 @@ public class DefaultTbelInvokeService extends AbstractScriptInvokeService implem
protected final Map<UUID, String> scriptIdToHash = new ConcurrentHashMap<>();
protected final Map<String, TbelScript> scriptMap = new ConcurrentHashMap<>();
private final String tbelSwitch = "switch";
private final String tbelSwitchErrorMsg = "TBEL does not support the 'switch'.";
protected Cache<String, Serializable> compiledScriptsCache;
private SandboxedParserConfiguration parserConfig;
@ -181,6 +184,9 @@ public class DefaultTbelInvokeService extends AbstractScriptInvokeService implem
}
return scriptId;
} catch (Exception e) {
if (((CompileException) e).getExpr() != null && new String(((CompileException) e).getExpr()).contains(tbelSwitch)) {
e = new CompileException(tbelSwitchErrorMsg, ((CompileException) e).getExpr(), ((CompileException) e).getCursor(), e.getCause());
}
throw new TbScriptException(scriptId, TbScriptException.ErrorCode.COMPILATION, scriptBody, e);
}
});

10
ui-ngx/src/app/shared/models/ace/tbel/worker-tbel.js

@ -5229,6 +5229,10 @@ var JSHINT = (function() {
var a = [], p;
while (!state.tokens.next.reach && state.tokens.next.id !== "(end)") {
if (state.tokens.next.value === "switch") {
warning("E067", state.tokens.next, "switch");
break;
}
if (state.tokens.next.id === ";") {
p = peek();
@ -9215,7 +9219,7 @@ var JSHINT = (function() {
statements(0);
}
if (state.tokens.next.id !== "(end)") {
if (state.tokens.next.id !== "(end)"&& state.tokens.next.value !== "switch") {
quit("E041", state.tokens.curr);
}
@ -11266,7 +11270,8 @@ var errors = {
E064: "Super call may only be used within class method bodies.",
E065: "Functions defined outside of strict mode with non-simple parameter lists may not " +
"enable strict mode.",
E066: "Asynchronous iteration is only available with for-of loops."
E066: "Asynchronous iteration is only available with for-of loops.",
E067: "Expected without the 'switch' statement. TBEL does not support the 'switch' statement."
};
var warnings = {
@ -11364,7 +11369,6 @@ var warnings = {
W086: "Expected a 'break' statement before '{a}'.",
W087: "Forgotten 'debugger' statement?",
W088: "Creating global 'for' variable. Should be 'for (var {a} ...'.",
// W288: "The syntax of function '{a}' is specific to TBEL, and is not supported by JS executor.",
W089: "The body of a for in should be wrapped in an if statement to filter " +
"unwanted properties from the prototype.",
W090: "'{a}' is not a statement label.",

Loading…
Cancel
Save