Skip to content

Instantly share code, notes, and snippets.

@FrankGrimm
Created December 30, 2010 12:47
Show Gist options
  • Save FrankGrimm/759753 to your computer and use it in GitHub Desktop.
Save FrankGrimm/759753 to your computer and use it in GitHub Desktop.
var _safecharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@%_-+=:,./";
// Original: http://phpjs.org/functions/escapeshellarg:866
exports.escapeshellargs = function(argument) {
var res = '';
argument.split('').forEach(function(c) {
if (_safecharacters.indexOf(c) > -1) {
res += c;
} else {
res += '\\' + c;
}
})
return res;
}
console.log(exports.escapeshellargs("node foo.js; rm -rf /"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment