properly fix leading '/' script bug (#296)

This commit is contained in:
Mughur 2023-01-06 03:33:30 +02:00 committed by GitHub
parent aa32e235fa
commit 3281b785ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

@ -421,9 +421,6 @@ export function runScriptFromScript(
return 0; return 0;
} }
//prevent leading / from causing a bug
if (scriptname.startsWith("/")) scriptname = scriptname.slice(1);
if (typeof scriptname !== "string" || !Array.isArray(args)) { if (typeof scriptname !== "string" || !Array.isArray(args)) {
workerScript.log(caller, () => `Invalid arguments: scriptname='${scriptname} args='${args}'`); workerScript.log(caller, () => `Invalid arguments: scriptname='${scriptname} args='${args}'`);
console.error(`runScriptFromScript() failed due to invalid arguments`); console.error(`runScriptFromScript() failed due to invalid arguments`);

@ -129,7 +129,12 @@ export abstract class BaseServer {
*/ */
getRunningScript(scriptName: string, scriptArgs: ScriptArg[]): RunningScript | null { getRunningScript(scriptName: string, scriptArgs: ScriptArg[]): RunningScript | null {
for (const rs of this.runningScripts) { 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; return rs;
} }
} }