Skip to content
This repository was archived by the owner on Apr 7, 2021. It is now read-only.

Commit f80a970

Browse files
chrmoritzzkat
authored andcommitted
fix(exec): fixed unix binary pathing issues (#120)
with special characters, which were incorrectly escaped with surrounding quotation marks causing child_process.spawn to throw an ENOENT error.
1 parent 52c2be2 commit f80a970

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function installPackages (specs, prefix, opts) {
232232
return opts.npm
233233
}
234234
}).then(npmPath => {
235-
return child.escapeArg(npmPath, true)
235+
return process.platform === 'win32' ? child.escapeArg(npmPath, true) : npmPath
236236
}).then(npmPath => {
237237
return child.spawn(npmPath, args, {
238238
stdio: [0, 'pipe', opts.q ? 'ignore' : 2]

test/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,22 @@ test('installPackages unit', t => {
9898
const err = new Error('npm failed')
9999
err.exitCode = 123
100100
return Promise.reject(err)
101+
} else if (args[2] === 'pathTest') {
102+
return Promise.resolve({
103+
stdout: JSON.stringify(npmPath)
104+
})
101105
} else {
102106
return Promise.resolve({
103107
stdout: JSON.stringify([].slice.call(arguments))
104108
})
105109
}
106110
},
107111
escapeArg (arg) {
112+
if (arg === '/f@ke_/path to/node'){
113+
return '\'/f@ke_/path to/node\''
114+
} else if (arg === 'C:\\f@ke_\\path to\\node'){
115+
return '"C:\\f@ke_\\path to\\node"'
116+
}
108117
return arg
109118
}
110119
}
@@ -141,6 +150,22 @@ test('installPackages unit', t => {
141150
)
142151
t.equal(err.exitCode, 123, 'error has exitCode')
143152
})
153+
}).then(() => {
154+
const nodePath = process.argv[0]
155+
process.argv[0] = isWindows ? 'C:\\f@ke_\\path to\\node' : '/f@ke_/path to/node'
156+
return installPkgs(['pathTest'], 'myprefix', {
157+
npm: NPM_PATH
158+
}).then((npmPath) => {
159+
process.argv[0] = nodePath
160+
if (isWindows){
161+
t.equal(npmPath, '"C:\\f@ke_\\path to\\node"', 'incorrectly escaped path win32')
162+
} else {
163+
t.equal(npmPath, '/f@ke_/path to/node', 'incorrectly escaped path *nix')
164+
}
165+
}, (e) => {
166+
process.argv[0] = nodePath
167+
throw new Error('should not have failed')
168+
})
144169
})
145170
})
146171

0 commit comments

Comments
 (0)