From 7ecac539f9963515b320c3b7ed87ff0209ce561f Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 20 Mar 2021 23:15:18 +0100 Subject: [PATCH] Fix path stripping for relative and Windows paths Fix path stripping logic to take into account the possibility of the writePath being relative, and that Windows uses \ as a path separator for some paths but not all. --- packages/lib/factorio/server.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/lib/factorio/server.js b/packages/lib/factorio/server.js index 474e4ebd..005727b7 100644 --- a/packages/lib/factorio/server.js +++ b/packages/lib/factorio/server.js @@ -543,14 +543,18 @@ class FactorioServer extends events.EventEmitter { this._gameReady = false; if (options.stripPaths) { - let chars = new Set(this.writePath("temp")); + let chars = new Set(path.resolve(this.writePath("temp"))); chars.delete(":"); // Having a colon could lead to matching the line number chars = [...chars].join(""); + let tempPath = `${path.resolve(this.writePath("temp", "currently-playing"))}${path.sep}`; + let writePath = `${path.resolve(this.writePath())}${path.sep}`; this._stripRegExp = new RegExp( - `(${escapeRegExp(this.writePath("temp", "currently-playing", path.sep))})|` + - `(${escapeRegExp(this.writePath(path.sep))})|` + - `(\\.\\.\\.[${escapeRegExp(chars)}]*?currently-playing\\${path.sep})`, + // The script printer formats paths using / on both windows and linux. + // But the save path is printed with \ on windows and / on linux. + `(${escapeRegExp(tempPath.replace(/\\/g, "/"))})|` + + `(${escapeRegExp(writePath)})|` + + `(\\.\\.\\.[${escapeRegExp(chars)}/]*?currently-playing/)`, "g" ); }