@e-mc/module 0.8.22 → 0.8.23

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 +5 -5
  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
- - https://www.unpkg.com/@e-mc/types@0.8.22/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.23/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -231,10 +231,10 @@ interface ModuleConstructor {
231
231
 
232
232
  ## References
233
233
 
234
- - https://www.unpkg.com/@e-mc/types@0.8.22/lib/core.d.ts
235
- - https://www.unpkg.com/@e-mc/types@0.8.22/lib/logger.d.ts
236
- - https://www.unpkg.com/@e-mc/types@0.8.22/lib/module.d.ts
237
- - https://www.unpkg.com/@e-mc/types@0.8.22/lib/node.d.ts
234
+ - https://www.unpkg.com/@e-mc/types@0.8.23/lib/core.d.ts
235
+ - https://www.unpkg.com/@e-mc/types@0.8.23/lib/logger.d.ts
236
+ - https://www.unpkg.com/@e-mc/types@0.8.23/lib/module.d.ts
237
+ - https://www.unpkg.com/@e-mc/types@0.8.23/lib/node.d.ts
238
238
 
239
239
  ## LICENSE
240
240
 
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',
@@ -714,7 +716,7 @@ class Module extends EventEmitter {
714
716
  this[_f] = new AbortController();
715
717
  this[_g] = null;
716
718
  }
717
- static get VERSION() { return "0.8.22"; }
719
+ static get VERSION() { return "0.8.23"; }
718
720
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
719
721
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
720
722
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -2090,12 +2092,10 @@ class Module extends EventEmitter {
2090
2092
  }
2091
2093
  static sanitizeArgs(values, doubleQuote) {
2092
2094
  const result = typeof values === 'string' ? [values] : values;
2093
- const pattern = /[^\w+-.,/:@]/g;
2094
- const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
2095
2095
  for (let i = 0; i < result.length; ++i) {
2096
2096
  let value = result[i].trim(), leading = '';
2097
2097
  if (value !== '--') {
2098
- const opt = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/.exec(value);
2098
+ const opt = REGEXP_CLIOPTION.exec(value);
2099
2099
  if (opt) {
2100
2100
  if (!opt[2] && !opt[3]) {
2101
2101
  result[i] = opt[1];
@@ -2105,7 +2105,7 @@ class Module extends EventEmitter {
2105
2105
  value = opt[3];
2106
2106
  }
2107
2107
  if (value) {
2108
- const quoted = /^(["'])(.*)\1$/.exec(value);
2108
+ const quoted = /^(["'])(.*)\1$/s.exec(value);
2109
2109
  if (PLATFORM_WIN32) {
2110
2110
  if (quoted) {
2111
2111
  if (quoted[1] === '"') {
@@ -2118,33 +2118,19 @@ class Module extends EventEmitter {
2118
2118
  value = wrapQuote(value);
2119
2119
  }
2120
2120
  }
2121
- else {
2122
- let type = doubleQuote;
2123
- if (quoted) {
2124
- if (quoted[1] === "'") {
2125
- result[i] = leading + value;
2126
- continue;
2127
- }
2128
- value = quoted[2];
2129
- type = true;
2130
- }
2131
- if (pattern.test(value)) {
2132
- if (type) {
2133
- value = '"' + sanitize(value) + '"';
2134
- }
2135
- else {
2136
- value = "'" + value.replace(/'/g, "'\\''") + "'";
2137
- }
2121
+ else if (!quoted) {
2122
+ if (REGEXP_CLIESCAPE.test(value)) {
2123
+ value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replace(/'/g, "'\\''")}'`;
2138
2124
  }
2139
2125
  else if (RESERVED_SHELL.includes(value)) {
2140
- value = "'" + value + "'";
2126
+ value = `'${value}'`;
2141
2127
  }
2142
2128
  }
2143
2129
  }
2144
2130
  else if (opt) {
2145
2131
  leading = leading.trim();
2146
2132
  if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
2147
- leading = sanitize(leading);
2133
+ leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
2148
2134
  }
2149
2135
  }
2150
2136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.8.22",
3
+ "version": "0.8.23",
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": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.8.22",
23
+ "@e-mc/types": "0.8.23",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",