Throw Error objects in inventoryImports/interfacingFunctions

Change throwing of strings objcts to throw proper Error objects.
This commit is contained in:
Hornwitser committed 2019-08-24 11:25:40 +02:00
1 parent 940a7b9180
commit a39a17b220
2 files changed
+3 -3

No files matched your search

@@ -11,7 +11,7 @@ function parseJsString(string){
// since eval is unsafe, maybe use https://www.npmjs.com/package/eval-sanitizer
if(string.includes("require") || string.includes(";") || string.includes("eval")){
throw "parseJsString might have gotten something that could be a xss attempt";
throw new Error("parseJsString might have gotten something that could be a xss attempt");
}
let inventory = "";
eval("inventory = " + string);
@@ -119,7 +119,7 @@ function insertItemsFromObject(confirmedItems, playerName){
// we gotta construct a string because I can't find any nice library for this
if(playerName && confirmedItems){
if(typeof playerName != "string") {
throw "playerName is: '"+typeof playerName+"' instead of string!";
throw new Error("playerName is: '"+typeof playerName+"' instead of string!");
}
let itemTable = "{";
Object.keys(confirmedItems).forEach(function(name){
@@ -141,7 +141,7 @@ describe("inventoryImports/interfacingFunctions.js", function(){
it("Throws if player name is not a string", function(){
assert.throws(function(){
let x = functions.insertItemsFromObject(testObject, testObject);
}, "playerName is: 'object' instead of string!");
}, Error("playerName is: 'object' instead of string!"));
});
it("Returns a big factorio command as string", function(){
let x = functions.insertItemsFromObject(testObject, playerName);