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

Commit

Permalink
Make argument escaping optional and turned off by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijs committed Feb 20, 2014
1 parent f18dbd8 commit c2e4d82
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions rsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Rsync.prototype.patterns = function(patterns) {
throw new Error('Invalid pattern');
}
}, this);
}
};

/**
* Exclude a file pattern from transfer. The pattern will be appended to the ordered list
Expand All @@ -286,7 +286,7 @@ Rsync.prototype.exclude = function(patterns) {
}, this);

return this;
}
};

/**
* Include a file pattern for transfer. The pattern will be appended to the ordered list
Expand All @@ -308,7 +308,7 @@ Rsync.prototype.include = function(patterns) {
}, this);

return this;
}
};

/**
* Get the command that is going to be executed.
Expand Down Expand Up @@ -418,7 +418,7 @@ Rsync.prototype.output = function(stdout, stderr) {
}

return this;
}
};

/**
* Execute the rsync command.
Expand Down Expand Up @@ -726,10 +726,15 @@ function exposeLongOption(option, name) {
/**
* Build an option for use in a shell command.
* @param {String} name
* @param {String} vlaue
* @param {String} value
* @param {Boolean} escape
* @return {String}
*/
function buildOption(name, value) {
function buildOption(name, value, escape) {
// Make sure the escape argument is a Boolean
escape = !!escape;

// Detect single option key
var single = (name.length === 1) ? true : false;

// Decide on prefix and value glue
Expand All @@ -739,7 +744,8 @@ function buildOption(name, value) {
// Build the option
var option = prefix + name;
if (arguments.length > 1 && value) {
option += glue + escapeShellArg(String(value));
value = (!escape) ? String(value) : escapeShellArg(String(value));
option += glue + value;
}

return option;
Expand All @@ -748,10 +754,12 @@ function buildOption(name, value) {
/**
* Escape an argument for use in a shell command.
* @param {String} arg
* @param {String} char
* @return {String}
*/
function escapeShellArg(arg) {
return '"' + arg.replace(/(["'`\\])/g, '\\$1') + '"';
function escapeShellArg(arg, char) {
char = char || '"';
return char + arg.replace(/(["'`\\])/g, '\\$1') + char;
}

/**
Expand Down

0 comments on commit c2e4d82

Please sign in to comment.