@j-o-r/sh 1.1.10 → 1.1.11
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 +16 -4
- package/package.json +1 -1
package/lib/SH.js
CHANGED
|
@@ -98,10 +98,22 @@ const SH = new Proxy(function(pieces, ...args) {
|
|
|
98
98
|
while (i < args.length) {
|
|
99
99
|
let s;
|
|
100
100
|
if (Array.isArray(args[i])) {
|
|
101
|
-
s = args[i].map((x) =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
s = args[i].map((x) => {
|
|
102
|
+
let str = String(x);
|
|
103
|
+
// If the string contains special characters, wrap in single quotes
|
|
104
|
+
if (str.match(/[ "'$`(){}[\]]/)) {
|
|
105
|
+
// Escape single quotes within the string
|
|
106
|
+
return `'${str.replace(/'/g, `'\\''`)}'`;
|
|
107
|
+
}
|
|
108
|
+
return str;
|
|
109
|
+
}).join(' ');
|
|
110
|
+
} else {
|
|
111
|
+
let str = String(args[i]);
|
|
112
|
+
if (str.match(/[ "'$`(){}[\]]/)) {
|
|
113
|
+
s = `'${str.replace(/'/g, `'\\''`)}'`;
|
|
114
|
+
} else {
|
|
115
|
+
s = str;
|
|
116
|
+
}
|
|
105
117
|
}
|
|
106
118
|
cmd += s + pieces[++i];
|
|
107
119
|
}
|
package/package.json
CHANGED