@j-o-r/sh 1.1.16 → 1.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/SH.js +4 -10
- package/lib/SHExecute.js +0 -1
- package/package.json +1 -1
package/lib/SH.js
CHANGED
|
@@ -99,9 +99,12 @@ const SH = new Proxy(function(pieces, ...args) {
|
|
|
99
99
|
let cmd = pieces[0], i = 0;
|
|
100
100
|
while (i < args.length) {
|
|
101
101
|
let s;
|
|
102
|
+
|
|
102
103
|
if (Array.isArray(args[i])) {
|
|
103
104
|
s = args[i].map(/** @param {string} x */(x) => {
|
|
104
|
-
|
|
105
|
+
// Trim every element
|
|
106
|
+
let str = String(x).trim();
|
|
107
|
+
str = str.replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t');
|
|
105
108
|
// If the string contains special characters, wrap in single quotes
|
|
106
109
|
if (str.match(/[ "'$`(){}[\]]/)) {
|
|
107
110
|
// Escape single quotes within the string
|
|
@@ -110,15 +113,6 @@ const SH = new Proxy(function(pieces, ...args) {
|
|
|
110
113
|
return str;
|
|
111
114
|
}).join(' ');
|
|
112
115
|
} else {
|
|
113
|
-
// let str = String(args[i]);
|
|
114
|
-
// if (str.match(/[ "'$`(){}[\]]/)) {
|
|
115
|
-
// s = `'${str.replace(/'/g, `'\\''`)}'`;
|
|
116
|
-
// } else {
|
|
117
|
-
// s = str;
|
|
118
|
-
// }
|
|
119
|
-
// Leave string UNALTERED
|
|
120
|
-
// Should be escaped in the code and is the responsibility of the developer
|
|
121
|
-
// SH`do something "${filename}"`;
|
|
122
116
|
s = String(args[i]);
|
|
123
117
|
}
|
|
124
118
|
cmd += s + pieces[++i];
|
package/lib/SHExecute.js
CHANGED
package/package.json
CHANGED