Skip to content

Commit

Permalink
Escape exec *args* only if space
Browse files Browse the repository at this point in the history
This matches npm's functionality. It's also been tested against the "some\"file" test, etc. It's hard too...and late.
  • Loading branch information
remy committed Jan 14, 2015
1 parent c7f9660 commit 9651ab8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/config/exec.js
Expand Up @@ -69,10 +69,12 @@ function parseExecutable(str) {
execArgs.push(token);
}

return {
var result = {
exec: exec,
execArgs: execArgs,
};

return result;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions lib/monitor/run.js
Expand Up @@ -47,6 +47,13 @@ function run(options) {
shFlag = '/c';
}

cmd.args = cmd.args.map(function (arg) {
if (arg.indexOf(' ') !== -1) {
arg = '"' + arg.replace(/"/g, '\\"') + '"';
}
return arg;
});

var args = [cmd.executable].concat(cmd.args).join(' ').trim();
var spawnArgs = [sh, [shFlag, args]];

Expand Down Expand Up @@ -96,6 +103,12 @@ function run(options) {
});

child.on('exit', function (code, signal) {
if (code === 2) {
// something wrong with parsed command
utils.log.error('failed to start process, possible issue with exec arguments');
process.exit();
}

// In case we killed the app ourselves, set the signal thusly
if (killedAfterChange) {
killedAfterChange = false;
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/some file
@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log(process.env.USER || 'OK');
2 changes: 2 additions & 0 deletions test/fixtures/some"file
@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log(process.env.USER || 'OK');

0 comments on commit 9651ab8

Please sign in to comment.