@e-mc/module 0.7.17 → 0.7.19

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/index.js +10 -24
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -117,6 +117,8 @@ const VALUES = {
117
117
  ["logger.level"]: -1
118
118
  };
119
119
  const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
120
+ const REGEXP_CLIESCAPE = /[^\w+-.,/:@]/g;
121
+ const REGEXP_CLIOPTION = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/s;
120
122
  const RESERVED_SHELL = [
121
123
  'if',
122
124
  'then',
@@ -586,7 +588,7 @@ class Module extends EventEmitter {
586
588
  this[_f] = new AbortController();
587
589
  this[_g] = null;
588
590
  }
589
- static get VERSION() { return "0.7.17"; }
591
+ static get VERSION() { return "0.7.19"; }
590
592
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
591
593
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
592
594
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -1900,12 +1902,10 @@ class Module extends EventEmitter {
1900
1902
  }
1901
1903
  static sanitizeArgs(values, doubleQuote) {
1902
1904
  const result = typeof values === 'string' ? [values] : values;
1903
- const pattern = /[^\w+-.,/:@]/g;
1904
- const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
1905
1905
  for (let i = 0; i < result.length; ++i) {
1906
1906
  let value = result[i].trim(), leading = '';
1907
1907
  if (value !== '--') {
1908
- const opt = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/.exec(value);
1908
+ const opt = REGEXP_CLIOPTION.exec(value);
1909
1909
  if (opt) {
1910
1910
  if (!opt[2] && !opt[3]) {
1911
1911
  result[i] = opt[1];
@@ -1915,7 +1915,7 @@ class Module extends EventEmitter {
1915
1915
  value = opt[3];
1916
1916
  }
1917
1917
  if (value) {
1918
- const quoted = /^(["'])(.*)\1$/.exec(value);
1918
+ const quoted = /^(["'])(.*)\1$/s.exec(value);
1919
1919
  if (PLATFORM_WIN32) {
1920
1920
  if (quoted) {
1921
1921
  if (quoted[1] === '"') {
@@ -1928,33 +1928,19 @@ class Module extends EventEmitter {
1928
1928
  value = wrapQuote(value);
1929
1929
  }
1930
1930
  }
1931
- else {
1932
- let type = doubleQuote;
1933
- if (quoted) {
1934
- if (quoted[1] === "'") {
1935
- result[i] = leading + value;
1936
- continue;
1937
- }
1938
- value = quoted[2];
1939
- type = true;
1940
- }
1941
- if (pattern.test(value)) {
1942
- if (type) {
1943
- value = '"' + sanitize(value) + '"';
1944
- }
1945
- else {
1946
- value = "'" + value.replace(/'/g, "'\\''") + "'";
1947
- }
1931
+ else if (!quoted) {
1932
+ if (REGEXP_CLIESCAPE.test(value)) {
1933
+ value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replace(/'/g, "'\\''")}'`;
1948
1934
  }
1949
1935
  else if (RESERVED_SHELL.includes(value)) {
1950
- value = "'" + value + "'";
1936
+ value = `'${value}'`;
1951
1937
  }
1952
1938
  }
1953
1939
  }
1954
1940
  else if (opt) {
1955
1941
  leading = leading.trim();
1956
1942
  if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
1957
- leading = sanitize(leading);
1943
+ leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
1958
1944
  }
1959
1945
  }
1960
1946
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.7.17",
3
+ "version": "0.7.19",
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.7.17",
23
+ "@e-mc/types": "0.7.19",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",