Skip to content
Browse files

add quote function

  • Loading branch information...
1 parent bd2f8df commit 22c9fcd13a4187e22a4c417db4787168ae4336ec @chjj committed Apr 11, 2012
Showing with 8 additions and 9 deletions.
  1. +8 −9 lib/daemonic.js
View
17 lib/daemonic.js
@@ -124,7 +124,7 @@ function fork(argv, opt) {
// cwd
opt.cwd = opt.cwd
- ? 'cd "' + opt.cwd.replace(/(["$\\])/g, '\\$1') + '" && '
+ ? 'cd ' + quote(opt.cwd) + ' && '
: '';
// umask
@@ -138,10 +138,7 @@ function fork(argv, opt) {
: '';
// escape arguments
- argv = argv.map(function(arg) {
- arg = arg.replace(/(["$\\])/g, '\\$1');
- return '"' + arg + '"';
- }).join(' ');
+ argv = argv.map(quote).join(' ');
// dup2
if (opt.customFds) {
@@ -179,18 +176,20 @@ function fork(argv, opt) {
return ps;
}
+function quote(arg) {
+ return '"' + arg.replace(/(["$\\])/g, '\\$1') + '"';
+}
+
function env(env) {
var keys = Object.keys(env)
, l = keys.length
, i = 0
, out = []
- , key
- , val;
+ , key;
for (; i < l; i++) {
key = keys[i];
- val = env[key].replace(/(["$\\])/g, '\\$1');
- out.push(key + '="' + val + '"');
+ out.push(key + '=' + quote(env[key]));
}
return out.join(' ');

0 comments on commit 22c9fcd

Please sign in to comment.
Something went wrong with that request. Please try again.