add function WTVShared.fixPathSlashes()

This commit is contained in:
zefie
2021-08-13 17:01:23 -04:00
parent 549848613c
commit f5e5289052

View File

@@ -166,7 +166,7 @@ class WTVShared {
} else { } else {
// already absolute path // already absolute path
} }
return path; return this.fixPathSlashes(path);
} }
/** /**
@@ -206,11 +206,25 @@ class WTVShared {
*/ */
makeSafePath(base, target) { makeSafePath(base, target) {
target.replace(/[\|\&\;\$\%\@\"\<\>\+\,\\]/g, ""); target.replace(/[\|\&\;\$\%\@\"\<\>\+\,\\]/g, "");
if (this.path.sep != "/") target = target.replace(/\//g, this.path.sep);
var targetPath = this.path.posix.normalize(target) var targetPath = this.path.posix.normalize(target)
return base + this.path.sep + targetPath; return this.fixPathSlashes(base + this.path.sep + targetPath);
} }
/**
* Corrects any / or \ differences, if any for file paths
* @param {string} path
* @returns {string} corrected path
*/
fixPathSlashes(path) {
// fix slashes
if (this.path.sep == '/' && path.indexOf("\\") != -1) path = path.replace(/\\/g, this.path.sep);
else if (this.path.sep == "\\" && path.indexOf("/") != -1) path = path.replace(/\//g, this.path.sep);
// remove double slashes
while (path.indexOf(this.path.sep + this.path.sep) != -1) path = path.replace(this.path.sep + this.path.sep, this.path.sep);
return path;
}
/** /**
* Makes sure an SSID is clean, and doesn't contain any exploitable characters * Makes sure an SSID is clean, and doesn't contain any exploitable characters
* @param {string} ssid * @param {string} ssid