@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.
Files changed (2) hide show
  1. package/lib/SH.js +16 -4
  2. 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) => x).join(' ');
102
- }
103
- else {
104
- s = args[i];
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
@@ -2,7 +2,7 @@
2
2
  "name": "@j-o-r/sh",
3
3
  "author": "Jorrit Duin <j-o-r@duin.work>",
4
4
  "type": "module",
5
- "version": "1.1.10",
5
+ "version": "1.1.11",
6
6
  "description": "Execute shell commands on Linux-based systems from javascript",
7
7
  "main": "lib/SH.js",
8
8
  "types": "types/SH.d.ts",