mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-15 18:08:32 -07:00
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 <koenkanters94@gmail.com>
This commit is contained in:
parent
489d1de756
commit
4bc0c3ed6b
@ -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 {
|
||||
|
@ -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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user