mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-26 08:33:12 +09:00
Throw Error objects in inventoryImports/interfacingFunctions
Change throwing of strings objcts to throw proper Error objects.
This commit is contained in:
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
|
// since eval is unsafe, maybe use https://www.npmjs.com/package/eval-sanitizer
|
||||||
if(string.includes("require") || string.includes(";") || string.includes("eval")){
|
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 = "";
|
let inventory = "";
|
||||||
eval("inventory = " + string);
|
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
|
// we gotta construct a string because I can't find any nice library for this
|
||||||
if(playerName && confirmedItems){
|
if(playerName && confirmedItems){
|
||||||
if(typeof playerName != "string") {
|
if(typeof playerName != "string") {
|
||||||
throw "playerName is: '"+typeof playerName+"' instead of string!";
|
throw new Error("playerName is: '"+typeof playerName+"' instead of string!");
|
||||||
}
|
}
|
||||||
let itemTable = "{";
|
let itemTable = "{";
|
||||||
Object.keys(confirmedItems).forEach(function(name){
|
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(){
|
it("Throws if player name is not a string", function(){
|
||||||
assert.throws(function(){
|
assert.throws(function(){
|
||||||
let x = functions.insertItemsFromObject(testObject, testObject);
|
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(){
|
it("Returns a big factorio command as string", function(){
|
||||||
let x = functions.insertItemsFromObject(testObject, playerName);
|
let x = functions.insertItemsFromObject(testObject, playerName);
|
||||||
|
|||||||
Reference in new issue
Block a user