From 3281b785ce6fcc956cdc8cda80d08cd487bd3f74 Mon Sep 17 00:00:00 2001 From: Mughur Date: Fri, 6 Jan 2023 03:33:30 +0200 Subject: [PATCH] properly fix leading '/' script bug (#296) --- src/NetscriptWorker.ts | 3 --- src/Server/BaseServer.ts | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/NetscriptWorker.ts b/src/NetscriptWorker.ts index cf9189db7..0b2e49ab8 100644 --- a/src/NetscriptWorker.ts +++ b/src/NetscriptWorker.ts @@ -421,9 +421,6 @@ export function runScriptFromScript( return 0; } - //prevent leading / from causing a bug - if (scriptname.startsWith("/")) scriptname = scriptname.slice(1); - if (typeof scriptname !== "string" || !Array.isArray(args)) { workerScript.log(caller, () => `Invalid arguments: scriptname='${scriptname} args='${args}'`); console.error(`runScriptFromScript() failed due to invalid arguments`); diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts index 7cdbc6250..0a4434f00 100644 --- a/src/Server/BaseServer.ts +++ b/src/Server/BaseServer.ts @@ -129,7 +129,12 @@ export abstract class BaseServer { */ getRunningScript(scriptName: string, scriptArgs: ScriptArg[]): RunningScript | null { for (const rs of this.runningScripts) { - if (rs.filename === scriptName && compareArrays(rs.args, scriptArgs)) { + //compare file names without leading '/' to prevent running multiple script with the same name + if ( + (rs.filename.charAt(0) == "/" ? rs.filename.slice(1) : rs.filename) === + (scriptName.charAt(0) == "/" ? scriptName.slice(1) : scriptName) && + compareArrays(rs.args, scriptArgs) + ) { return rs; } }