diff options
| author | Jacob Richman <[email protected]> | 2025-05-01 18:02:04 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-01 18:02:04 -0700 |
| commit | 53ac7952c7ac11770037fecccda5f0f2fffa3e0b (patch) | |
| tree | 92309fd1cca72e8f4b1e645e0810b8fff8affdb6 /packages/server/src | |
| parent | ca53565240174eebbe0c03457a8444cae81e2747 (diff) | |
Support escaping spaces in file paths. (#241)
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, ' '); +} |
