Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Commit

Permalink
fix(exec): fixed unix binary pathing issues (#120)
Browse files Browse the repository at this point in the history
with special characters, which were incorrectly escaped with surrounding
quotation marks causing child_process.spawn to throw an ENOENT error.
  • Loading branch information
chrmoritz authored and zkat committed Oct 18, 2017
1 parent 52c2be2 commit f80a970
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function installPackages (specs, prefix, opts) {
return opts.npm
}
}).then(npmPath => {
return child.escapeArg(npmPath, true)
return process.platform === 'win32' ? child.escapeArg(npmPath, true) : npmPath
}).then(npmPath => {
return child.spawn(npmPath, args, {
stdio: [0, 'pipe', opts.q ? 'ignore' : 2]
Expand Down
25 changes: 25 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,22 @@ test('installPackages unit', t => {
const err = new Error('npm failed')
err.exitCode = 123
return Promise.reject(err)
} else if (args[2] === 'pathTest') {
return Promise.resolve({
stdout: JSON.stringify(npmPath)
})
} else {
return Promise.resolve({
stdout: JSON.stringify([].slice.call(arguments))
})
}
},
escapeArg (arg) {
if (arg === '/f@ke_/path to/node'){
return '\'/f@ke_/path to/node\''
} else if (arg === 'C:\\f@ke_\\path to\\node'){
return '"C:\\f@ke_\\path to\\node"'
}
return arg
}
}
Expand Down Expand Up @@ -141,6 +150,22 @@ test('installPackages unit', t => {
)
t.equal(err.exitCode, 123, 'error has exitCode')
})
}).then(() => {
const nodePath = process.argv[0]
process.argv[0] = isWindows ? 'C:\\f@ke_\\path to\\node' : '/f@ke_/path to/node'
return installPkgs(['pathTest'], 'myprefix', {
npm: NPM_PATH
}).then((npmPath) => {
process.argv[0] = nodePath
if (isWindows){
t.equal(npmPath, '"C:\\f@ke_\\path to\\node"', 'incorrectly escaped path win32')
} else {
t.equal(npmPath, '/f@ke_/path to/node', 'incorrectly escaped path *nix')
}
}, (e) => {
process.argv[0] = nodePath
throw new Error('should not have failed')
})
})
})

Expand Down

0 comments on commit f80a970

Please sign in to comment.