Extend broken parseJs method for "n > x" syntax

More of an hack than anything


Bug introduced in 423ae8977e
SD-9217
This commit is contained in:
Christian Koop 2022-06-16 13:20:07 +02:00
parent 771b3eaf70
commit 1a4d33879a
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
1 changed files with 14 additions and 0 deletions

View File

@ -99,6 +99,20 @@ public class GeneralUtils {
}
public static Object parseJS(String toParse, String type, Object def) {
if (toParse.trim().matches("^\\d+\\s+(<|>)\\s*\\d+$")) { // e.g. "1 < 2"
toParse = toParse.trim();
double firstNumber = Double.parseDouble(toParse.substring(0, toParse.indexOf(" ")));
String symbol = toParse.substring(toParse.indexOf(" ") + 1, toParse.indexOf(" ") + 2);
double secondNumber = Double.parseDouble(toParse.substring(toParse.indexOf(" ") + 2));
if (symbol.equals(">")) {
return firstNumber > secondNumber;
}
return firstNumber < secondNumber;
}
// FIXME: JavaScript != Math...
// Input "false ? (8 * 3) : (4 * 3)" fails for obvious reasons
return MathUtils.eval(toParse, "[EpicEnchants] One of your " + type + " expressions is not properly formatted.");