You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
469 B
18 lines
469 B
2 years ago
|
module.exports = shellescape;
|
||
|
|
||
|
// return a shell compatible format
|
||
|
function shellescape(a) {
|
||
|
var ret = [];
|
||
|
|
||
|
a.forEach(function(s) {
|
||
|
if (!/^[A-Za-z0-9_\/-]+$/.test(s)) {
|
||
|
s = "'"+s.replace(/'/g,"'\\''")+"'";
|
||
|
s = s.replace(/^(?:'')+/g, '') // unduplicate single-quote at the beginning
|
||
|
.replace(/\\'''/g, "\\'" ); // remove non-escaped single-quote if there are enclosed between 2 escaped
|
||
|
}
|
||
|
ret.push(s);
|
||
|
});
|
||
|
|
||
|
return ret.join(' ');
|
||
|
}
|