Skip to content

Commit 4b57069

Browse files
committed
fix(paths): replace path.sep with normalizePath across codebase
Replace platform-specific path.sep usage with normalized paths for consistent cross-platform behavior: - bootstrap.mts: Use path.join(...segments).replace(/\\/g, '/') for tarball paths - bootstrap.mts: Normalize path.relative() result and use '../' instead of path.sep - home-path.mts: Normalize cwd before regex matching, simplify pattern to '/' All paths now use forward slashes consistently regardless of platform.
1 parent e297a1c commit 4b57069

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

packages/cli/src/stub/bootstrap.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ function sanitizeTarballPath(filePath: string): string {
8181
const segments = withoutPrefix
8282
.split('/')
8383
.filter(seg => seg && seg !== '.' && seg !== '..')
84-
// Normalize path separators for the current platform.
85-
return segments.join(path.sep)
84+
// Use path.join for proper path construction, then normalize to forward slashes.
85+
return path.join(...segments).replace(/\\/g, '/')
8686
}
8787

8888
/**
@@ -106,11 +106,11 @@ async function remove(
106106
}
107107

108108
// Check if trying to delete outside SOCKET_HOME (catastrophic delete protection).
109-
const relation = path.relative(SOCKET_HOME, absolutePath)
109+
const relation = path.relative(SOCKET_HOME, absolutePath).replace(/\\/g, '/')
110110
const isInside = Boolean(
111111
relation &&
112112
relation !== '..' &&
113-
!relation.startsWith(`..${path.sep}`) &&
113+
!relation.startsWith('../') &&
114114
!path.isAbsolute(relation),
115115
)
116116

packages/cli/src/utils/fs/home-path.mts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@
1111
* - Common Unix convention for home directory
1212
*/
1313

14-
import path from 'node:path'
15-
1614
import { escapeRegExp } from '@socketsecurity/lib/regexps'
15+
import { normalizePath } from '@socketsecurity/lib/path'
1716

1817
import { homePath } from '../../constants/paths.mts'
1918

2019
export function tildify(cwd: string) {
21-
// On Windows, accept both forward and back slashes as separators
22-
// since paths can be mixed (Git Bash, WSL, etc.).
23-
const sepPattern = path.sep === '\\' ? '[\\\\/]' : '/'
24-
return cwd.replace(
25-
new RegExp(`^${escapeRegExp(homePath)}(?:${sepPattern}|$)`, 'i'),
20+
// Normalize to forward slashes for consistent matching across platforms.
21+
const normalizedCwd = normalizePath(cwd)
22+
return normalizedCwd.replace(
23+
new RegExp(`^${escapeRegExp(homePath)}(?:/|$)`, 'i'),
2624
'~/',
2725
)
2826
}

0 commit comments

Comments
 (0)