Only allow one reference to MP in sell price (#156)

This commit is contained in:
Snarling 2022-10-25 08:51:37 -04:00 committed by GitHub
parent 3f0a7786f8
commit a79621612f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -95,8 +95,9 @@ export function SellMaterial(mat: Material, amt: string, price: string): void {
if (amt === "") amt = "0"; if (amt === "") amt = "0";
let cost = price.replace(/\s+/g, ""); let cost = price.replace(/\s+/g, "");
cost = cost.replace(/[^-()\d/*+.MPe]/g, ""); //Sanitize cost cost = cost.replace(/[^-()\d/*+.MPe]/g, ""); //Sanitize cost
let temp = cost.replace(/MP/g, mat.bCost + ""); let temp = cost.replace(/MP/, mat.bCost + "");
try { try {
if (temp.includes("MP")) throw "Only one reference to MP is allowed in sell price.";
temp = eval(temp); temp = eval(temp);
} catch (e) { } catch (e) {
throw new Error("Invalid value or expression for sell price field: " + e); throw new Error("Invalid value or expression for sell price field: " + e);
@ -154,9 +155,10 @@ export function SellProduct(product: Product, city: string, amt: string, price:
//Dynamically evaluated quantity. First test to make sure its valid //Dynamically evaluated quantity. First test to make sure its valid
//Sanitize input, then replace dynamic variables with arbitrary numbers //Sanitize input, then replace dynamic variables with arbitrary numbers
price = price.replace(/\s+/g, ""); price = price.replace(/\s+/g, "");
price = price.replace(/[^-()\d/*+.MP]/g, ""); price = price.replace(/[^-()\d/*+.MPe]/g, "");
let temp = price.replace(/MP/g, "1"); let temp = price.replace(/MP/, product.pCost + "");
try { try {
if (temp.includes("MP")) throw "Only one reference to MP is allowed in sell price.";
temp = eval(temp); temp = eval(temp);
} catch (e) { } catch (e) {
throw new Error("Invalid value or expression for sell price field: " + e); throw new Error("Invalid value or expression for sell price field: " + e);