From efc2209c0f9a61194eba0c47e8511c5fb930b085 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 22 Nov 2011 17:44:51 +0100 Subject: [PATCH] Prevented overwriting built-in constants. --- .../java/com/sk89q/worldedit/expression/Expression.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/expression/Expression.java b/src/main/java/com/sk89q/worldedit/expression/Expression.java index 108d18d64..8c08a45f0 100644 --- a/src/main/java/com/sk89q/worldedit/expression/Expression.java +++ b/src/main/java/com/sk89q/worldedit/expression/Expression.java @@ -26,7 +26,6 @@ import java.util.Map; import com.sk89q.worldedit.expression.lexer.Lexer; import com.sk89q.worldedit.expression.lexer.tokens.Token; import com.sk89q.worldedit.expression.parser.Parser; -import com.sk89q.worldedit.expression.parser.ParserException; import com.sk89q.worldedit.expression.runtime.Constant; import com.sk89q.worldedit.expression.runtime.EvaluationException; import com.sk89q.worldedit.expression.runtime.RValue; @@ -69,13 +68,18 @@ public class Expression { this(Lexer.tokenize(expression), variableNames); } - private Expression(List tokens, String... variableNames) throws ParserException { + private Expression(List tokens, String... variableNames) throws ExpressionException { this.variableNames = variableNames; + variables.put("e", new Constant(-1, Math.E)); variables.put("pi", new Constant(-1, Math.PI)); variables.put("true", new Constant(-1, 1)); variables.put("false", new Constant(-1, 0)); + for (String variableName : variableNames) { + if (variables.containsKey(variableName)) { + throw new ExpressionException(-1, "Tried to overwrite identifier '" + variableName + "'"); + } variables.put(variableName, new Variable(0)); }