1 | var lameShellEscape = require('shell-escape');
|
2 |
|
3 | module.exports = shellEscape;
|
4 |
|
5 | function shellEscape(args){
|
6 | var pipes = ['<', '>', '>>', '|', '&>', '2>&1', '&&', ';', '||'];
|
7 | var breaks = args.map(function(arg, i){
|
8 | return {
|
9 | arg: arg,
|
10 | i: i
|
11 | };
|
12 | }).filter(function(item){
|
13 | return (pipes.indexOf(item.arg) !== -1);
|
14 | }).map(function(item){
|
15 | return item.i;
|
16 | });
|
17 |
|
18 | return args.reduce(function(command, arg, i){
|
19 | if (breaks.indexOf(i) === -1) {
|
20 | command.push(lameShellEscape([arg]));
|
21 | } else {
|
22 | command.push(arg);
|
23 | }
|
24 | return command;
|
25 | }, []).join(' ');
|
26 | } |
\ | No newline at end of file |