From 4bc0c3ed6bd053ac93f06008845ce3447df72126 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Sun, 13 Nov 2022 09:24:47 +0100 Subject: [PATCH] Use path.resolve instead of path.join in data.joinPath (#14953) This allows specifying a path outside of the data directory using an absolute path (e.g. /path/to/devices.yaml) or a path relative to the data directory (e.g. devices.yaml, foo/devices.yaml, ../../devices.yaml, ...). This change is backward compatible because file names and nested paths are just a special case of a relative path. Co-authored-by: Koen Kanters --- lib/util/data.ts | 2 +- test/data.test.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/util/data.ts b/lib/util/data.ts index c49fa4956..b30ed1711 100644 --- a/lib/util/data.ts +++ b/lib/util/data.ts @@ -14,7 +14,7 @@ function load(): void { load(); function joinPath(file: string): string { - return path.join(dataPath, file); + return path.resolve(dataPath, file); } function getPath(): string { diff --git a/test/data.test.js b/test/data.test.js index 877b249d6..ca7f958ca 100644 --- a/test/data.test.js +++ b/test/data.test.js @@ -19,6 +19,7 @@ describe('Data', () => { const actual = data.getPath(); expect(actual).toBe(expected); expect(data.joinPath('test')).toStrictEqual(path.join(expected, 'test')); + expect(data.joinPath('/test')).toStrictEqual(path.resolve(expected, '/test')); delete process.env.ZIGBEE2MQTT_DATA; data.testingOnlyReload(); });