diff options
Diffstat (limited to 'packages/server/src')
| -rw-r--r-- | packages/server/src/utils/paths.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/server/src/utils/paths.ts b/packages/server/src/utils/paths.ts index f1a42131..6da3d4ab 100644 --- a/packages/server/src/utils/paths.ts +++ b/packages/server/src/utils/paths.ts @@ -100,3 +100,26 @@ export function makeRelative( // If the paths are the same, path.relative returns '', return '.' instead return relativePath || '.'; } + +/** + * Escapes spaces in a file path. + */ +export function escapePath(filePath: string): string { + let result = ''; + for (let i = 0; i < filePath.length; i++) { + // Only escape spaces that are not already escaped. + if (filePath[i] === ' ' && (i === 0 || filePath[i - 1] !== '\\')) { + result += '\\ '; + } else { + result += filePath[i]; + } + } + return result; +} + +/** + * Unescapes spaces in a file path. + */ +export function unescapePath(filePath: string): string { + return filePath.replace(/\\ /g, ' '); +} |
