shell-escape.js 469 B

1234567891011121314151617
  1. module.exports = shellescape;
  2. // return a shell compatible format
  3. function shellescape(a) {
  4. var ret = [];
  5. a.forEach(function(s) {
  6. if (!/^[A-Za-z0-9_\/-]+$/.test(s)) {
  7. s = "'"+s.replace(/'/g,"'\\''")+"'";
  8. s = s.replace(/^(?:'')+/g, '') // unduplicate single-quote at the beginning
  9. .replace(/\\'''/g, "\\'" ); // remove non-escaped single-quote if there are enclosed between 2 escaped
  10. }
  11. ret.push(s);
  12. });
  13. return ret.join(' ');
  14. }