Fix error on dash in instance name

Fix stripPaths logic breaking when the instance name contains RegExp
meta characters due to a lack of escaping.
This commit is contained in:
Hornwitser committed 2020-11-10 22:13:07 +01:00
1 parent 4c9b91ab57
commit 31c0925354
2 files changed
+11 -1

No files matched your search

+1 -1
View File
@@ -554,7 +554,7 @@ class FactorioServer extends events.EventEmitter {
this._stripRegExp = new RegExp(
`(${escapeRegExp(this.writePath("temp", "currently-playing", path.sep))})|` +
`(${escapeRegExp(this.writePath(path.sep))})|` +
`(\\.\\.\\.[${chars}]*?currently-playing\\${path.sep})`,
`(\\.\\.\\.[${escapeRegExp(chars)}]*?currently-playing\\${path.sep})`,
"g"
);
}
+10
View File
@@ -170,6 +170,16 @@ describe("lib/factorio/server", function() {
let writePath = path.join("temp", "test", "server");
let server = new libFactorio.FactorioServer(path.join("test", "file", "factorio"), writePath, {});
describe("constructor()", function() {
it("should handle dashes in write path with strapPaths enabled", function() {
new libFactorio.FactorioServer(
path.join("test", "file", "factorio"),
path.join("temp", "test", "server-1"),
{ stripPaths: true }
);
});
});
describe(".init()", function() {
it("should not throw on first call", async function() {
await server.init();