@e-mc/module 0.9.16 → 0.9.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.
Files changed (3) hide show
  1. package/README.md +6 -6
  2. package/index.js +10 -24
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.9.16/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.17/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -394,11 +394,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
394
394
 
395
395
  ## References
396
396
 
397
- - https://www.unpkg.com/@e-mc/types@0.9.16/lib/core.d.ts
398
- - https://www.unpkg.com/@e-mc/types@0.9.16/lib/logger.d.ts
399
- - https://www.unpkg.com/@e-mc/types@0.9.16/lib/module.d.ts
400
- - https://www.unpkg.com/@e-mc/types@0.9.16/lib/node.d.ts
401
- - https://www.unpkg.com/@e-mc/types@0.9.16/lib/settings.d.ts
397
+ - https://www.unpkg.com/@e-mc/types@0.9.17/lib/core.d.ts
398
+ - https://www.unpkg.com/@e-mc/types@0.9.17/lib/logger.d.ts
399
+ - https://www.unpkg.com/@e-mc/types@0.9.17/lib/module.d.ts
400
+ - https://www.unpkg.com/@e-mc/types@0.9.17/lib/node.d.ts
401
+ - https://www.unpkg.com/@e-mc/types@0.9.17/lib/settings.d.ts
402
402
 
403
403
  * https://www.npmjs.com/package/@types/node
404
404
 
package/index.js CHANGED
@@ -129,6 +129,8 @@ const MEMORY_CACHE_DISK = {
129
129
  exclude: null
130
130
  };
131
131
  const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
132
+ const REGEXP_CLIESCAPE = /[^\w+-.,/:@]/g;
133
+ const REGEXP_CLIOPTION = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/s;
132
134
  const RESERVED_SHELL = [
133
135
  'if',
134
136
  'then',
@@ -738,7 +740,7 @@ class Module extends EventEmitter {
738
740
  this[_f] = new AbortController();
739
741
  this[_g] = null;
740
742
  }
741
- static get VERSION() { return "0.9.16"; }
743
+ static get VERSION() { return "0.9.17"; }
742
744
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
743
745
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
744
746
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -2164,12 +2166,10 @@ class Module extends EventEmitter {
2164
2166
  }
2165
2167
  static sanitizeArgs(values, doubleQuote) {
2166
2168
  const result = typeof values === 'string' ? [values] : values;
2167
- const pattern = /[^\w+-.,/:@]/g;
2168
- const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
2169
2169
  for (let i = 0; i < result.length; ++i) {
2170
2170
  let value = result[i].trim(), leading = '';
2171
2171
  if (value !== '--') {
2172
- const opt = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/.exec(value);
2172
+ const opt = REGEXP_CLIOPTION.exec(value);
2173
2173
  if (opt) {
2174
2174
  if (!opt[2] && !opt[3]) {
2175
2175
  result[i] = opt[1];
@@ -2179,7 +2179,7 @@ class Module extends EventEmitter {
2179
2179
  value = opt[3];
2180
2180
  }
2181
2181
  if (value) {
2182
- const quoted = /^(["'])(.*)\1$/.exec(value);
2182
+ const quoted = /^(["'])(.*)\1$/s.exec(value);
2183
2183
  if (PLATFORM_WIN32) {
2184
2184
  if (quoted) {
2185
2185
  if (quoted[1] === '"') {
@@ -2192,33 +2192,19 @@ class Module extends EventEmitter {
2192
2192
  value = wrapQuote(value);
2193
2193
  }
2194
2194
  }
2195
- else {
2196
- let type = doubleQuote;
2197
- if (quoted) {
2198
- if (quoted[1] === "'") {
2199
- result[i] = leading + value;
2200
- continue;
2201
- }
2202
- value = quoted[2];
2203
- type = true;
2204
- }
2205
- if (pattern.test(value)) {
2206
- if (type) {
2207
- value = '"' + sanitize(value) + '"';
2208
- }
2209
- else {
2210
- value = "'" + value.replace(/'/g, "'\\''") + "'";
2211
- }
2195
+ else if (!quoted) {
2196
+ if (REGEXP_CLIESCAPE.test(value)) {
2197
+ value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replaceAll("'", "'\\''")}'`;
2212
2198
  }
2213
2199
  else if (RESERVED_SHELL.includes(value)) {
2214
- value = "'" + value + "'";
2200
+ value = `'${value}'`;
2215
2201
  }
2216
2202
  }
2217
2203
  }
2218
2204
  else if (opt) {
2219
2205
  leading = leading.trim();
2220
2206
  if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
2221
- leading = sanitize(leading);
2207
+ leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
2222
2208
  }
2223
2209
  }
2224
2210
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.9.16",
3
+ "version": "0.9.17",
4
4
  "description": "Module base class for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "license": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.9.16",
23
+ "@e-mc/types": "0.9.17",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "16.5.4",
26
26
  "js-yaml": "^4.1.0",