@j-o-r/sh 1.1.10 → 1.1.12

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 +21 -4
  2. package/package.json +2 -3
package/lib/SH.js CHANGED
@@ -89,6 +89,7 @@ const parseDuration = (d) => {
89
89
  }
90
90
  throw new Error(`Unknown duration: "${d}".`);
91
91
  }
92
+
92
93
  /** @type {Shell & { (pieces: TemplateStringsArray, ...args: *): SHDispatch }} */
93
94
  const SH = new Proxy(function(pieces, ...args) {
94
95
  if (pieces.some((p) => p == undefined)) {
@@ -98,10 +99,26 @@ const SH = new Proxy(function(pieces, ...args) {
98
99
  while (i < args.length) {
99
100
  let s;
100
101
  if (Array.isArray(args[i])) {
101
- s = args[i].map((x) => x).join(' ');
102
- }
103
- else {
104
- s = args[i];
102
+ s = args[i].map(/** @param {string} x */(x) => {
103
+ let str = String(x);
104
+ // If the string contains special characters, wrap in single quotes
105
+ if (str.match(/[ "'$`(){}[\]]/)) {
106
+ // Escape single quotes within the string
107
+ return `'${str.replace(/'/g, `'\\''`)}'`;
108
+ }
109
+ return str;
110
+ }).join(' ');
111
+ } else {
112
+ // let str = String(args[i]);
113
+ // if (str.match(/[ "'$`(){}[\]]/)) {
114
+ // s = `'${str.replace(/'/g, `'\\''`)}'`;
115
+ // } else {
116
+ // s = str;
117
+ // }
118
+ // Leave string UNALTERED
119
+ // Should be escaped in the code and is the responsibility of the developer
120
+ // SH`do something "${filename}"`;
121
+ s = String(args[i]);
105
122
  }
106
123
  cmd += s + pieces[++i];
107
124
  }
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.12",
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",
@@ -14,8 +14,7 @@
14
14
  "test:sh": "scenarios/sh.js",
15
15
  "publish": "npm run release && npm publish --access public",
16
16
  "release": "npm pack --pack-destination=release",
17
- "types": "tsc -p tsc.json",
18
- "clear:types": "rm types/*.d.ts"
17
+ "types": "rm types/* && tsc -p tsc.json"
19
18
  },
20
19
  "repository": {
21
20
  "type": "git",