diff --git a/package-lock.json b/package-lock.json index 97a4e64..7c5d55a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@filen/sync", - "version": "0.1.8", + "version": "0.1.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@filen/sync", - "version": "0.1.8", + "version": "0.1.10", "license": "AGPLv3", "dependencies": { "@filen/sdk": "^0.1.134", diff --git a/package.json b/package.json index af7a13c..92783f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@filen/sync", - "version": "0.1.10", + "version": "0.1.11", "description": "Filen Sync", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/utils.ts b/src/utils.ts index 988e7c6..f4bf8a0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -107,17 +107,23 @@ export const isValidPath = memoize((inputPath: string): boolean => { // eslint-disable-next-line no-control-regex const illegalCharsLinux = /[\x00]/ + if (process.platform === "win32") { + inputPath = inputPath.replace(/\\/g, "/") + } + if (inputPath.includes("..")) { return false } - const normalizedPath = pathModule.normalize(inputPath) - const parts = normalizedPath.split(pathModule.sep) + const parts = inputPath.split("/") switch (process.platform) { case "win32": { for (const part of parts) { - if (part.trim() === "") { + const trimmed = part.trim() + + // Skip drive letter + if (trimmed.length === 0 || (trimmed.length === 2 && part.endsWith(":") && inputPath.startsWith(part))) { continue } @@ -131,11 +137,7 @@ export const isValidPath = memoize((inputPath: string): boolean => { const nameParts = part.split(".") - if (nameParts[0] && reservedNamesWindows.test(nameParts[0]) && nameParts.length > 1) { - return false - } - - if (part.endsWith(".") || part.endsWith(" ")) { + if (nameParts[0] && nameParts[0].length > 0 && reservedNamesWindows.test(nameParts[0])) { return false } } @@ -145,17 +147,13 @@ export const isValidPath = memoize((inputPath: string): boolean => { case "darwin": { for (const part of parts) { - if (part.trim() === "") { + if (part.trim().length === 0) { continue } if (illegalCharsMacOS.test(part)) { return false } - - if (part.startsWith(".")) { - continue - } } return true @@ -163,17 +161,13 @@ export const isValidPath = memoize((inputPath: string): boolean => { case "linux": { for (const part of parts) { - if (part.trim() === "") { + if (part.trim().length === 0) { continue } if (illegalCharsLinux.test(part)) { return false } - - if (part === ".") { - continue - } } return true