Skip to content

Commit d593920

Browse files
zkochanclaude
andcommitted
refactor: move proxyVarSubDir validation to shared path-extender
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3fa2d15 commit d593920

3 files changed

Lines changed: 11 additions & 28 deletions

File tree

os/env/path-extender-posix/path-extender-posix.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,10 @@ export async function addDirToPosixEnvPath (
4343
dir: string,
4444
opts: AddDirToPosixEnvPathOpts
4545
): Promise<PathExtenderPosixReport> {
46-
if (opts.proxyVarSubDir) {
47-
validateSubDir(opts.proxyVarSubDir)
48-
}
4946
const currentShell = detectCurrentShell()
5047
return await updateShell(currentShell, dir, opts)
5148
}
5249

53-
function validateSubDir (subDir: string): void {
54-
if (
55-
subDir.startsWith('/') ||
56-
subDir.startsWith('\\') ||
57-
subDir.includes('..') ||
58-
/[;\n\r"'`$%|<>&]/.test(subDir)
59-
) {
60-
throw new PnpmError('INVALID_SUBDIR', `Invalid proxyVarSubDir: "${subDir}"`)
61-
}
62-
}
63-
6450
function detectCurrentShell () {
6551
if (process.env.ZSH_VERSION) return 'zsh'
6652
if (process.env.BASH_VERSION) return 'bash'

os/env/path-extender-windows/path-extender-windows.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,7 @@ export async function addDirToWindowsEnvPath (dir: string, opts?: AddDirToWindow
6161

6262
export type EnvVariableChangeAction = 'skipped' | 'updated'
6363

64-
function validateSubDir (subDir: string): void {
65-
if (
66-
subDir.startsWith('/') ||
67-
subDir.startsWith('\\') ||
68-
subDir.includes('..') ||
69-
/[;%"'`<>&]/.test(subDir)
70-
) {
71-
throw new PnpmError('INVALID_SUBDIR', `Invalid proxyVarSubDir: "${subDir}"`)
72-
}
73-
}
74-
7564
async function _addDirToWindowsEnvPath (dir: string, opts: AddDirToWindowsEnvPathOpts = {}): Promise<PathExtenderWindowsReport> {
76-
if (opts.proxyVarSubDir) {
77-
validateSubDir(opts.proxyVarSubDir)
78-
}
7965
const addedDir = path.normalize(dir)
8066
const registryOutput = await getRegistryOutput()
8167
const changes: PathExtenderWindowsReport = []

os/env/path-extender/path-extender.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PnpmError } from '@pnpm/error'
12
import {
23
addDirToPosixEnvPath,
34
AddDirToPosixEnvPathOpts,
@@ -14,6 +15,16 @@ export type PathExtenderReport = Pick<PathExtenderPosixReport, 'oldSettings' | '
1415
export type AddDirToEnvPathOpts = AddDirToPosixEnvPathOpts
1516

1617
export async function addDirToEnvPath(dir: string, opts: AddDirToEnvPathOpts): Promise<PathExtenderReport> {
18+
if (opts.proxyVarSubDir) {
19+
if (
20+
opts.proxyVarSubDir.startsWith('/') ||
21+
opts.proxyVarSubDir.startsWith('\\') ||
22+
opts.proxyVarSubDir.includes('..') ||
23+
/[;%"'`$<>&|\n\r]/.test(opts.proxyVarSubDir)
24+
) {
25+
throw new PnpmError('INVALID_SUBDIR', `Invalid proxyVarSubDir: "${opts.proxyVarSubDir}"`)
26+
}
27+
}
1728
if (process.platform === 'win32') {
1829
return renderWindowsReport(await addDirToWindowsEnvPath(dir, {
1930
position: opts.position,

0 commit comments

Comments
 (0)