@theia/process 1.72.0-next.52 → 1.72.0

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.
@@ -1,92 +1,6 @@
1
1
  /**
2
- * Defines how an argument should be quoted if it contains
3
- * spaces or unsupported characters.
2
+ * Re-exported from `@theia/core` for backwards compatibility.
3
+ * Prefer importing from `@theia/core/lib/common/shell-quoting` directly.
4
4
  */
5
- export declare const enum ShellQuoting {
6
- /**
7
- * Character escaping should be used. This for example
8
- * uses \ on bash and ` on PowerShell.
9
- */
10
- Escape = "escape",
11
- /**
12
- * Strong string quoting should be used. This for example
13
- * uses " for Windows cmd and ' for bash and PowerShell.
14
- * Strong quoting treats arguments as literal strings.
15
- * Under PowerShell echo 'The value is $(2 * 3)' will
16
- * print `The value is $(2 * 3)`
17
- */
18
- Strong = "strong",
19
- /**
20
- * Weak string quoting should be used. This for example
21
- * uses " for Windows cmd, bash and PowerShell. Weak quoting
22
- * still performs some kind of evaluation inside the quoted
23
- * string. Under PowerShell echo "The value is $(2 * 3)"
24
- * will print `The value is 6`
25
- */
26
- Weak = "weak"
27
- }
28
- /**
29
- * A string that will be quoted depending on the used shell.
30
- */
31
- export interface ShellQuotedString {
32
- /**
33
- * The actual string value.
34
- */
35
- value: string;
36
- /**
37
- * The quoting style to use.
38
- */
39
- quoting: ShellQuoting;
40
- }
41
- /**
42
- * Functions that provide shell quoting capabilities.
43
- */
44
- export interface ShellQuotingFunctions {
45
- characters: {
46
- /** Characters that require quotes, white space is always implied. */
47
- needQuotes?: string;
48
- /** The character used to escape sequences. */
49
- escape?: string;
50
- /** The character used to quote sequences, preventing variable expansion. */
51
- strong?: string;
52
- /** The character used to quote sequences, allowing variable expansion. */
53
- weak?: string;
54
- };
55
- /**
56
- * Should add escape-characters in front of forbidden characters.
57
- */
58
- escape?(this: any, arg: string): string;
59
- /**
60
- * Should quote the argument in such a way that variables CANNOT be expanded.
61
- */
62
- strong?(this: any, arg: string): string;
63
- /**
64
- * Should quote the argument in such a way that variables CAN be expanded.
65
- */
66
- weak?(this: any, arg: string): string;
67
- }
68
- /**
69
- * Converts a list of args into an escaped shell command.
70
- *
71
- * There are two main use cases when handling command/arguments for a shell:
72
- * 1. User already wrote the escaped commandline, then just use that.
73
- * 2. User wants a specific process to be invoked with some arguments.
74
- *
75
- * The `createShellCommandLine` function is useful for the latter.
76
- *
77
- * @param args Standard list of spawn/exec arguments, first item is the command.
78
- * @param quotingFunctions Collection of functions to process arguments.
79
- */
80
- export declare function createShellCommandLine(args: Array<string | ShellQuotedString>, quotingFunctions?: ShellQuotingFunctions): string;
81
- /**
82
- * Escape (or quote) a given input.
83
- *
84
- * @param arg Input to escape.
85
- * @param quotingFunctions Collection of functions to process the given `arg`.
86
- * @param quotingType Override the quoting type specified by the given `arg`.
87
- */
88
- export declare function escapeForShell(arg: string | ShellQuotedString, quotingFunctions?: ShellQuotingFunctions, quotingType?: ShellQuoting): string;
89
- export declare const BashQuotingFunctions: Required<ShellQuotingFunctions>;
90
- export declare const CmdQuotingFunctions: Required<ShellQuotingFunctions>;
91
- export declare const PowershellQuotingFunctions: Required<ShellQuotingFunctions>;
5
+ export { ShellQuoting, ShellQuotedString, ShellQuotingFunctions, createShellCommandLine, escapeForShell, BashQuotingFunctions, CmdQuotingFunctions, PowershellQuotingFunctions } from '@theia/core/lib/common/shell-quoting';
92
6
  //# sourceMappingURL=shell-quoting.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell-quoting.d.ts","sourceRoot":"","sources":["../../src/common/shell-quoting.ts"],"names":[],"mappings":"AAyBA;;;GAGG;AACH,0BAAkB,YAAY;IAE1B;;;OAGG;IACH,MAAM,WAAW;IAEjB;;;;;;OAMG;IACH,MAAM,WAAW;IAEjB;;;;;;OAMG;IACH,IAAI,SAAS;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,E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ACZ,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,0BAA0B,EAC7B,MAAM,sCAAsC,CAAC"}
@@ -15,132 +15,15 @@
15
15
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
16
  // *****************************************************************************
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.PowershellQuotingFunctions = exports.CmdQuotingFunctions = exports.BashQuotingFunctions = void 0;
19
- exports.createShellCommandLine = createShellCommandLine;
20
- exports.escapeForShell = escapeForShell;
18
+ exports.PowershellQuotingFunctions = exports.CmdQuotingFunctions = exports.BashQuotingFunctions = exports.escapeForShell = exports.createShellCommandLine = void 0;
21
19
  /**
22
- * Converts a list of args into an escaped shell command.
23
- *
24
- * There are two main use cases when handling command/arguments for a shell:
25
- * 1. User already wrote the escaped commandline, then just use that.
26
- * 2. User wants a specific process to be invoked with some arguments.
27
- *
28
- * The `createShellCommandLine` function is useful for the latter.
29
- *
30
- * @param args Standard list of spawn/exec arguments, first item is the command.
31
- * @param quotingFunctions Collection of functions to process arguments.
20
+ * Re-exported from `@theia/core` for backwards compatibility.
21
+ * Prefer importing from `@theia/core/lib/common/shell-quoting` directly.
32
22
  */
33
- function createShellCommandLine(args, quotingFunctions) {
34
- return args.map(arg => escapeForShell(arg, quotingFunctions)).join(' ');
35
- }
36
- /**
37
- * Escape (or quote) a given input.
38
- *
39
- * @param arg Input to escape.
40
- * @param quotingFunctions Collection of functions to process the given `arg`.
41
- * @param quotingType Override the quoting type specified by the given `arg`.
42
- */
43
- function escapeForShell(arg, quotingFunctions, quotingType) {
44
- let value;
45
- let quoting = quotingType;
46
- if (typeof arg === 'string') {
47
- if (!quoting) {
48
- return arg;
49
- }
50
- value = arg;
51
- }
52
- else {
53
- if (!quoting) {
54
- quoting = arg.quoting;
55
- }
56
- value = arg.value;
57
- }
58
- if (quotingFunctions && typeof quotingFunctions[quoting] === 'function') {
59
- return quotingFunctions[quoting](value);
60
- }
61
- return value;
62
- }
63
- exports.BashQuotingFunctions = {
64
- characters: {
65
- needQuotes: '()',
66
- escape: '\\',
67
- strong: '\'',
68
- weak: '"',
69
- },
70
- escape(arg) {
71
- return arg
72
- .replace(/[\s\\|(){}<>$&;"']/g, '\\$&');
73
- },
74
- strong(arg) {
75
- // ('+) becomes ('"'+"')
76
- return `'${arg
77
- .replace(/'+/g, '\'"$&"\'')}'`;
78
- },
79
- weak(arg) {
80
- return `"${arg
81
- // Escape escape-characters.
82
- .replace(/\\"/g, '\\\\"')
83
- // Escape user-specified double-quotes.
84
- .replace(/"/g, '\\"')
85
- // Escape trailing (\), we don't want the user to escape our last quote.
86
- .replace(/\\$/g, '\\\\')}"`;
87
- },
88
- };
89
- exports.CmdQuotingFunctions = {
90
- characters: {
91
- weak: '"',
92
- },
93
- escape(arg) {
94
- return arg
95
- // Escape forbidden characters (see: cmd /?).
96
- .replace(/[%&<>()@^|]/g, '^$&')
97
- // Some characters must be escaped using `\`.
98
- .replace(/[\\"]/g, '\\$&')
99
- // Double-quote whitespaces, else we cannot escape it.
100
- .replace(/\s+/g, '"$&"');
101
- },
102
- strong(arg) {
103
- return this.weak(arg)
104
- // Try to prevent variable expansion.
105
- .replace(/%/g, '"%"');
106
- },
107
- weak(arg) {
108
- return `"${arg
109
- // Escape double quotes.
110
- .replace(/\\"/g, '\\\\"')
111
- .replace(/"/g, '\\"')
112
- // Escape forbidden characters (see: cmd /?)
113
- .replace(/[&<>()@^|]/g, '^$&')
114
- // Escape trailing backslash, we don't want the user to escape our last quote.
115
- .replace(/\\$/g, '\\\\')
116
- // Escape line returns
117
- .replace(/\r?\n/g, '^$&')}"`;
118
- },
119
- };
120
- exports.PowershellQuotingFunctions = {
121
- characters: {
122
- needQuotes: '()',
123
- escape: '`',
124
- strong: '\'',
125
- weak: '"',
126
- },
127
- escape(arg) {
128
- return arg.replace(/[`|{}()<>;"' ]/g, '`$&');
129
- },
130
- strong(arg) {
131
- // In powershell, one must write ('') for a single quote to be displayed
132
- // within a single quoted string.
133
- return `'${arg
134
- .replace(/'/g, '\'\'')}'`;
135
- },
136
- weak(arg) {
137
- return `"${arg
138
- // Escape escape-characters.
139
- .replace(/`"/g, '``"')
140
- // Escape user-specified backticks.
141
- .replace(/"/g, '`"')
142
- // Escape trailing (`), we don't want the user to escape our last quote.
143
- .replace(/`$/g, '``')}"`;
144
- },
145
- };
23
+ var shell_quoting_1 = require("@theia/core/lib/common/shell-quoting");
24
+ Object.defineProperty(exports, "createShellCommandLine", { enumerable: true, get: function () { return shell_quoting_1.createShellCommandLine; } });
25
+ Object.defineProperty(exports, "escapeForShell", { enumerable: true, get: function () { return shell_quoting_1.escapeForShell; } });
26
+ Object.defineProperty(exports, "BashQuotingFunctions", { enumerable: true, get: function () { return shell_quoting_1.BashQuotingFunctions; } });
27
+ Object.defineProperty(exports, "CmdQuotingFunctions", { enumerable: true, get: function () { return shell_quoting_1.CmdQuotingFunctions; } });
28
+ Object.defineProperty(exports, "PowershellQuotingFunctions", { enumerable: true, get: function () { return shell_quoting_1.PowershellQuotingFunctions; } });
146
29
  //# sourceMappingURL=shell-quoting.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell-quoting.js","sourceRoot":"","sources":["../../src/common/shell-quoting.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AA0GhF,wDAEC;AASD,wCAkBC;AAzCD;;;;;;;;;;;GAWG;AACH,SAAgB,sBAAsB,CAAC,IAAuC,EAAE,gBAAwC;IACpH,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,gBAAgB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aACT,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC;IAClC,CAAC;IACD,IAAI,CAAC,GAAG;QACJ,OAAO,IAAI,GAAG;YACV,4BAA4B;aAC3B,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;YACtB,mCAAmC;aAClC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;YACpB,wEAAwE;aACvE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC;IACjC,CAAC;CACJ,CAAC"}
1
+ {"version":3,"file":"shell-quoting.js","sourceRoot":"","sources":["../../src/common/shell-quoting.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF;;;GAGG;AACH,sEAS8C;AAL1C,uHAAA,sBAAsB,OAAA;AACtB,+GAAA,cAAc,OAAA;AACd,qHAAA,oBAAoB,OAAA;AACpB,oHAAA,mBAAmB,OAAA;AACnB,2HAAA,0BAA0B,OAAA"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@theia/process",
3
- "version": "1.72.0-next.52+726081b2a",
3
+ "version": "1.72.0",
4
4
  "description": "Theia process support.",
5
5
  "dependencies": {
6
- "@theia/core": "1.72.0-next.52+726081b2a",
6
+ "@theia/core": "1.72.0",
7
7
  "node-pty": "1.2.0-beta.12",
8
8
  "string-argv": "^0.1.2",
9
9
  "tslib": "^2.8.1"
@@ -45,10 +45,10 @@
45
45
  "watch": "theiaext watch"
46
46
  },
47
47
  "devDependencies": {
48
- "@theia/ext-scripts": "1.71.0"
48
+ "@theia/ext-scripts": "1.72.0"
49
49
  },
50
50
  "nyc": {
51
51
  "extends": "../../configs/nyc.json"
52
52
  },
53
- "gitHead": "726081b2aa03827611ba4a323da1a6aaf0e9a9b9"
53
+ "gitHead": "5bc20bc672aa732fb7e05234cf63c1b514868896"
54
54
  }
@@ -14,223 +14,17 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- // #region vscode
18
-
19
- /*---------------------------------------------------------------------------------------------
20
- * Copyright (c) Microsoft Corporation. All rights reserved.
21
- * Licensed under the MIT License. See License.txt in the project root for license information.
22
- *--------------------------------------------------------------------------------------------*/
23
-
24
- // See: https://github.com/microsoft/vscode/blob/9ebb7c43bc99fd6e1a295040674d1f8e5831b9be/src/vs/vscode.d.ts#L5326-L5370
25
-
26
- /**
27
- * Defines how an argument should be quoted if it contains
28
- * spaces or unsupported characters.
29
- */
30
- export const enum ShellQuoting {
31
-
32
- /**
33
- * Character escaping should be used. This for example
34
- * uses \ on bash and ` on PowerShell.
35
- */
36
- Escape = 'escape',
37
-
38
- /**
39
- * Strong string quoting should be used. This for example
40
- * uses " for Windows cmd and ' for bash and PowerShell.
41
- * Strong quoting treats arguments as literal strings.
42
- * Under PowerShell echo 'The value is $(2 * 3)' will
43
- * print `The value is $(2 * 3)`
44
- */
45
- Strong = 'strong',
46
-
47
- /**
48
- * Weak string quoting should be used. This for example
49
- * uses " for Windows cmd, bash and PowerShell. Weak quoting
50
- * still performs some kind of evaluation inside the quoted
51
- * string. Under PowerShell echo "The value is $(2 * 3)"
52
- * will print `The value is 6`
53
- */
54
- Weak = 'weak'
55
- }
56
-
57
- /**
58
- * A string that will be quoted depending on the used shell.
59
- */
60
- export interface ShellQuotedString {
61
- /**
62
- * The actual string value.
63
- */
64
- value: string;
65
-
66
- /**
67
- * The quoting style to use.
68
- */
69
- quoting: ShellQuoting;
70
- }
71
-
72
- // #endregion vscode
73
-
74
17
  /**
75
- * Functions that provide shell quoting capabilities.
18
+ * Re-exported from `@theia/core` for backwards compatibility.
19
+ * Prefer importing from `@theia/core/lib/common/shell-quoting` directly.
76
20
  */
77
- export interface ShellQuotingFunctions {
78
-
79
- characters: {
80
- /** Characters that require quotes, white space is always implied. */
81
- needQuotes?: string
82
- /** The character used to escape sequences. */
83
- escape?: string
84
- /** The character used to quote sequences, preventing variable expansion. */
85
- strong?: string
86
- /** The character used to quote sequences, allowing variable expansion. */
87
- weak?: string
88
- }
89
-
90
- /**
91
- * Should add escape-characters in front of forbidden characters.
92
- */
93
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- escape?(this: any, arg: string): string
95
-
96
- /**
97
- * Should quote the argument in such a way that variables CANNOT be expanded.
98
- */
99
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
- strong?(this: any, arg: string): string;
101
-
102
- /**
103
- * Should quote the argument in such a way that variables CAN be expanded.
104
- */
105
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
- weak?(this: any, arg: string): string;
107
- }
108
-
109
- /**
110
- * Converts a list of args into an escaped shell command.
111
- *
112
- * There are two main use cases when handling command/arguments for a shell:
113
- * 1. User already wrote the escaped commandline, then just use that.
114
- * 2. User wants a specific process to be invoked with some arguments.
115
- *
116
- * The `createShellCommandLine` function is useful for the latter.
117
- *
118
- * @param args Standard list of spawn/exec arguments, first item is the command.
119
- * @param quotingFunctions Collection of functions to process arguments.
120
- */
121
- export function createShellCommandLine(args: Array<string | ShellQuotedString>, quotingFunctions?: ShellQuotingFunctions): string {
122
- return args.map(arg => escapeForShell(arg, quotingFunctions)).join(' ');
123
- }
124
-
125
- /**
126
- * Escape (or quote) a given input.
127
- *
128
- * @param arg Input to escape.
129
- * @param quotingFunctions Collection of functions to process the given `arg`.
130
- * @param quotingType Override the quoting type specified by the given `arg`.
131
- */
132
- export function escapeForShell(arg: string | ShellQuotedString, quotingFunctions?: ShellQuotingFunctions, quotingType?: ShellQuoting): string {
133
- let value: string;
134
- let quoting: ShellQuoting | undefined = quotingType;
135
- if (typeof arg === 'string') {
136
- if (!quoting) {
137
- return arg;
138
- }
139
- value = arg;
140
- } else {
141
- if (!quoting) {
142
- quoting = arg.quoting;
143
- }
144
- value = arg.value;
145
- }
146
- if (quotingFunctions && typeof quotingFunctions[quoting] === 'function') {
147
- return quotingFunctions[quoting]!(value);
148
- }
149
- return value;
150
- }
151
-
152
- export const BashQuotingFunctions: Required<ShellQuotingFunctions> = {
153
- characters: {
154
- needQuotes: '()',
155
- escape: '\\',
156
- strong: '\'',
157
- weak: '"',
158
- },
159
- escape(arg): string {
160
- return arg
161
- .replace(/[\s\\|(){}<>$&;"']/g, '\\$&');
162
- },
163
- strong(arg): string {
164
- // ('+) becomes ('"'+"')
165
- return `'${arg
166
- .replace(/'+/g, '\'"$&"\'')}'`;
167
- },
168
- weak(arg): string {
169
- return `"${arg
170
- // Escape escape-characters.
171
- .replace(/\\"/g, '\\\\"')
172
- // Escape user-specified double-quotes.
173
- .replace(/"/g, '\\"')
174
- // Escape trailing (\), we don't want the user to escape our last quote.
175
- .replace(/\\$/g, '\\\\')}"`;
176
- },
177
- };
178
-
179
- export const CmdQuotingFunctions: Required<ShellQuotingFunctions> = {
180
- characters: {
181
- weak: '"',
182
- },
183
- escape(arg): string {
184
- return arg
185
- // Escape forbidden characters (see: cmd /?).
186
- .replace(/[%&<>()@^|]/g, '^$&')
187
- // Some characters must be escaped using `\`.
188
- .replace(/[\\"]/g, '\\$&')
189
- // Double-quote whitespaces, else we cannot escape it.
190
- .replace(/\s+/g, '"$&"');
191
- },
192
- strong(arg): string {
193
- return this.weak(arg)
194
- // Try to prevent variable expansion.
195
- .replace(/%/g, '"%"');
196
- },
197
- weak(arg): string {
198
- return `"${arg
199
- // Escape double quotes.
200
- .replace(/\\"/g, '\\\\"')
201
- .replace(/"/g, '\\"')
202
- // Escape forbidden characters (see: cmd /?)
203
- .replace(/[&<>()@^|]/g, '^$&')
204
- // Escape trailing backslash, we don't want the user to escape our last quote.
205
- .replace(/\\$/g, '\\\\')
206
- // Escape line returns
207
- .replace(/\r?\n/g, '^$&')}"`;
208
- },
209
- };
210
-
211
- export const PowershellQuotingFunctions: Required<ShellQuotingFunctions> = {
212
- characters: {
213
- needQuotes: '()',
214
- escape: '`',
215
- strong: '\'',
216
- weak: '"',
217
- },
218
- escape(arg): string {
219
- return arg.replace(/[`|{}()<>;"' ]/g, '`$&');
220
- },
221
- strong(arg): string {
222
- // In powershell, one must write ('') for a single quote to be displayed
223
- // within a single quoted string.
224
- return `'${arg
225
- .replace(/'/g, '\'\'')}'`;
226
- },
227
- weak(arg): string {
228
- return `"${arg
229
- // Escape escape-characters.
230
- .replace(/`"/g, '``"')
231
- // Escape user-specified backticks.
232
- .replace(/"/g, '`"')
233
- // Escape trailing (`), we don't want the user to escape our last quote.
234
- .replace(/`$/g, '``')}"`;
235
- },
236
- };
21
+ export {
22
+ ShellQuoting,
23
+ ShellQuotedString,
24
+ ShellQuotingFunctions,
25
+ createShellCommandLine,
26
+ escapeForShell,
27
+ BashQuotingFunctions,
28
+ CmdQuotingFunctions,
29
+ PowershellQuotingFunctions
30
+ } from '@theia/core/lib/common/shell-quoting';
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=shell-quoting.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shell-quoting.spec.d.ts","sourceRoot":"","sources":["../../src/common/shell-quoting.spec.ts"],"names":[],"mappings":""}
@@ -1,171 +0,0 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2020 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const chai_1 = require("chai");
19
- const shell_quoting_1 = require("./shell-quoting");
20
- describe('Shell arguments escaping:', () => {
21
- // Procedurally execute tests from this list of data.
22
- const testData = {
23
- bash: {
24
- // https://www.gnu.org/software/bash/manual/html_node/Quoting.html
25
- quotingFunctions: shell_quoting_1.BashQuotingFunctions,
26
- data: {
27
- ["escape" /* ShellQuoting.Escape */]: [
28
- { input: 'abc', expected: 'abc' },
29
- { input: 'ab c', expected: 'ab\\ c' },
30
- { input: 'ab"c', expected: 'ab\\"c' },
31
- { input: 'ab\'c', expected: 'ab\\\'c' },
32
- { input: 'ab\\ c\\', expected: 'ab\\\\\\ c\\\\' },
33
- {
34
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
35
- expected: 'setTimeout\\(\\(\\)\\ =\\>\\ \\{\\ console.log\\(1,\\ \\"2\\\'3\\"\\)\\;\\ \\},\\ 100\\)',
36
- },
37
- ],
38
- ["strong" /* ShellQuoting.Strong */]: [
39
- { input: 'abc', expected: '\'abc\'' },
40
- { input: 'ab c', expected: '\'ab c\'' },
41
- { input: 'ab"c', expected: '\'ab"c\'' },
42
- { input: 'ab\'c', expected: '\'ab\'"\'"\'c\'' },
43
- { input: 'ab\\ c\\', expected: '\'ab\\ c\\\'' },
44
- {
45
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
46
- expected: '\'setTimeout(() => { console.log(1, "2\'"\'"\'3"); }, 100)\'',
47
- },
48
- ],
49
- ["weak" /* ShellQuoting.Weak */]: [
50
- { input: 'abc', expected: '"abc"' },
51
- { input: 'ab c', expected: '"ab c"' },
52
- { input: 'ab"c', expected: '"ab\\"c"' },
53
- { input: 'ab\'c', expected: '"ab\'c"' },
54
- { input: 'ab\\ c\\', expected: '"ab\\ c\\\\"' },
55
- {
56
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
57
- expected: '"setTimeout(() => { console.log(1, \\"2\'3\\"); }, 100)"',
58
- },
59
- ]
60
- },
61
- },
62
- cmd: {
63
- // https://ss64.com/nt/syntax-esc.html
64
- quotingFunctions: shell_quoting_1.CmdQuotingFunctions,
65
- data: {
66
- ["escape" /* ShellQuoting.Escape */]: [
67
- { input: 'abc', expected: 'abc' },
68
- { input: 'ab c', expected: 'ab" "c' },
69
- { input: 'ab"c', expected: 'ab\\"c' },
70
- { input: 'ab\'c', expected: 'ab\'c' },
71
- { input: 'ab^ c^', expected: 'ab^^" "c^^' },
72
- {
73
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
74
- expected: 'setTimeout^(^(^)" "=^>" "{" "console.log^(1," "\\"2\'3\\"^);" "}," "100^)',
75
- },
76
- {
77
- input: 'console.log("%PATH%")',
78
- expected: 'console.log^(\\"^%PATH^%\\"^)',
79
- },
80
- ],
81
- ["strong" /* ShellQuoting.Strong */]: [
82
- { input: 'abc', expected: '"abc"' },
83
- { input: 'ab c', expected: '"ab c"' },
84
- { input: 'ab"c', expected: '"ab\\"c"' },
85
- { input: 'ab\'c', expected: '"ab\'c"' },
86
- { input: 'ab^ c^', expected: '"ab^^ c^^"' },
87
- {
88
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
89
- expected: '"setTimeout^(^(^) =^> { console.log^(1, \\"2\'3\\"^); }, 100^)"',
90
- },
91
- {
92
- input: 'console.log("%PATH%")',
93
- expected: '"console.log^(\\""%"PATH"%"\\"^)"',
94
- },
95
- ],
96
- ["weak" /* ShellQuoting.Weak */]: [
97
- { input: 'abc', expected: '"abc"' },
98
- { input: 'ab c', expected: '"ab c"' },
99
- { input: 'ab"c', expected: '"ab\\"c"' },
100
- { input: 'ab\'c', expected: '"ab\'c"' },
101
- { input: 'ab^ c^', expected: '"ab^^ c^^"' },
102
- {
103
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
104
- expected: '"setTimeout^(^(^) =^> { console.log^(1, \\"2\'3\\"^); }, 100^)"',
105
- },
106
- {
107
- input: 'console.log("%PATH%")',
108
- expected: '"console.log^(\\"%PATH%\\"^)"',
109
- },
110
- ]
111
- },
112
- },
113
- powershell: {
114
- // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-6
115
- quotingFunctions: shell_quoting_1.PowershellQuotingFunctions,
116
- data: {
117
- ["escape" /* ShellQuoting.Escape */]: [
118
- { input: 'abc', expected: 'abc' },
119
- { input: 'ab c', expected: 'ab` c' },
120
- { input: 'ab"c', expected: 'ab`"c' },
121
- { input: 'ab\'c', expected: 'ab`\'c' },
122
- { input: 'ab` c`', expected: 'ab``` c``' },
123
- {
124
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
125
- expected: 'setTimeout`(`(`)` =`>` `{` console.log`(1,` `"2`\'3`"`)`;` `},` 100`)',
126
- },
127
- ],
128
- ["strong" /* ShellQuoting.Strong */]: [
129
- { input: 'abc', expected: '\'abc\'' },
130
- { input: 'ab c', expected: '\'ab c\'' },
131
- { input: 'ab"c', expected: '\'ab"c\'' },
132
- { input: 'ab\'c', expected: '\'ab\'\'c\'' },
133
- { input: 'ab` c`', expected: '\'ab` c`\'' },
134
- {
135
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
136
- expected: '\'setTimeout(() => { console.log(1, "2\'\'3"); }, 100)\'',
137
- },
138
- ],
139
- ["weak" /* ShellQuoting.Weak */]: [
140
- { input: 'abc', expected: '"abc"' },
141
- { input: 'ab c', expected: '"ab c"' },
142
- { input: 'ab"c', expected: '"ab`"c"' },
143
- { input: 'ab\'c', expected: '"ab\'c"' },
144
- { input: 'ab` c`', expected: '"ab` c``"' },
145
- {
146
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
147
- expected: '"setTimeout(() => { console.log(1, `"2\'3`"); }, 100)"',
148
- },
149
- ]
150
- },
151
- }
152
- };
153
- // Iter through each runtime (bash/cmd/powershell):
154
- for (const runtime of Object.keys(testData)) {
155
- const testInfo = testData[runtime];
156
- // Get all quoting types (escape/strong/weak):
157
- for (const quotingType of Object.keys(testInfo.data)) {
158
- const testInput = testInfo.data[quotingType];
159
- // Run the test for each input:
160
- it(`${runtime}/${quotingType}`, () => {
161
- for (const test of testInput) {
162
- (0, chai_1.expect)((0, shell_quoting_1.escapeForShell)({
163
- quoting: quotingType,
164
- value: test.input,
165
- }, testInfo.quotingFunctions)).equal(test.expected);
166
- }
167
- });
168
- }
169
- }
170
- });
171
- //# sourceMappingURL=shell-quoting.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shell-quoting.spec.js","sourceRoot":"","sources":["../../src/common/shell-quoting.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,+BAA8B;AAE9B,mDAAsI;AAEtI,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IAEvC,qDAAqD;IACrD,MAAM,QAAQ,GAAG;QACb,IAAI,EAAE;YACF,kEAAkE;YAClE,gBAAgB,EAAE,oCAAoB;YACtC,IAAI,EAAE;gBACF,oCAAqB,EAAE;oBACnB,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE;oBACjC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE;oBACrC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE;oBACrC,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE;oBACvC,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE;oBACjD;wBACI,KAAK,EAAE,oDAAoD;wBAC3D,QAAQ,EAAE,0FAA0F;qBACvG;iBACJ;gBACD,oCA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ACrE;iBACJ;aACJ;SACJ;KACK,CAAC;IAEX,mDAAmD;IACnD,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAgC,CAAC,CAAC;QAE5D,8CAA8C;QAC9C,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,WAA4C,CAAC,CAAC;YAE9E,+BAA+B;YAC/B,EAAE,CAAC,GAAG,OAAO,IAAI,WAAW,EAAE,EAAE,GAAG,EAAE;gBACjC,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;oBAC3B,IAAA,aAAM,EAAC,IAAA,8BAAc,EAAC;wBAClB,OAAO,EAAE,WAA2B;wBACpC,KAAK,EAAE,IAAI,CAAC,KAAK;qBACpB,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACxD,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;AAEL,CAAC,CAAC,CAAC"}
@@ -1,176 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2020 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { expect } from 'chai';
18
-
19
- import { escapeForShell, BashQuotingFunctions, ShellQuoting, CmdQuotingFunctions, PowershellQuotingFunctions } from './shell-quoting';
20
-
21
- describe('Shell arguments escaping:', () => {
22
-
23
- // Procedurally execute tests from this list of data.
24
- const testData = {
25
- bash: {
26
- // https://www.gnu.org/software/bash/manual/html_node/Quoting.html
27
- quotingFunctions: BashQuotingFunctions,
28
- data: {
29
- [ShellQuoting.Escape]: [
30
- { input: 'abc', expected: 'abc' },
31
- { input: 'ab c', expected: 'ab\\ c' },
32
- { input: 'ab"c', expected: 'ab\\"c' },
33
- { input: 'ab\'c', expected: 'ab\\\'c' },
34
- { input: 'ab\\ c\\', expected: 'ab\\\\\\ c\\\\' },
35
- {
36
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
37
- expected: 'setTimeout\\(\\(\\)\\ =\\>\\ \\{\\ console.log\\(1,\\ \\"2\\\'3\\"\\)\\;\\ \\},\\ 100\\)',
38
- },
39
- ],
40
- [ShellQuoting.Strong]: [
41
- { input: 'abc', expected: '\'abc\'' },
42
- { input: 'ab c', expected: '\'ab c\'' },
43
- { input: 'ab"c', expected: '\'ab"c\'' },
44
- { input: 'ab\'c', expected: '\'ab\'"\'"\'c\'' },
45
- { input: 'ab\\ c\\', expected: '\'ab\\ c\\\'' },
46
- {
47
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
48
- expected: '\'setTimeout(() => { console.log(1, "2\'"\'"\'3"); }, 100)\'',
49
- },
50
- ],
51
- [ShellQuoting.Weak]: [
52
- { input: 'abc', expected: '"abc"' },
53
- { input: 'ab c', expected: '"ab c"' },
54
- { input: 'ab"c', expected: '"ab\\"c"' },
55
- { input: 'ab\'c', expected: '"ab\'c"' },
56
- { input: 'ab\\ c\\', expected: '"ab\\ c\\\\"' },
57
- {
58
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
59
- expected: '"setTimeout(() => { console.log(1, \\"2\'3\\"); }, 100)"',
60
- },
61
- ]
62
- },
63
- },
64
- cmd: {
65
- // https://ss64.com/nt/syntax-esc.html
66
- quotingFunctions: CmdQuotingFunctions,
67
- data: {
68
- [ShellQuoting.Escape]: [
69
- { input: 'abc', expected: 'abc' },
70
- { input: 'ab c', expected: 'ab" "c' },
71
- { input: 'ab"c', expected: 'ab\\"c' },
72
- { input: 'ab\'c', expected: 'ab\'c' },
73
- { input: 'ab^ c^', expected: 'ab^^" "c^^' },
74
- {
75
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
76
- expected: 'setTimeout^(^(^)" "=^>" "{" "console.log^(1," "\\"2\'3\\"^);" "}," "100^)',
77
- },
78
- {
79
- input: 'console.log("%PATH%")',
80
- expected: 'console.log^(\\"^%PATH^%\\"^)',
81
- },
82
- ],
83
- [ShellQuoting.Strong]: [
84
- { input: 'abc', expected: '"abc"' },
85
- { input: 'ab c', expected: '"ab c"' },
86
- { input: 'ab"c', expected: '"ab\\"c"' },
87
- { input: 'ab\'c', expected: '"ab\'c"' },
88
- { input: 'ab^ c^', expected: '"ab^^ c^^"' },
89
- {
90
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
91
- expected: '"setTimeout^(^(^) =^> { console.log^(1, \\"2\'3\\"^); }, 100^)"',
92
- },
93
- {
94
- input: 'console.log("%PATH%")',
95
- expected: '"console.log^(\\""%"PATH"%"\\"^)"',
96
- },
97
- ],
98
- [ShellQuoting.Weak]: [
99
- { input: 'abc', expected: '"abc"' },
100
- { input: 'ab c', expected: '"ab c"' },
101
- { input: 'ab"c', expected: '"ab\\"c"' },
102
- { input: 'ab\'c', expected: '"ab\'c"' },
103
- { input: 'ab^ c^', expected: '"ab^^ c^^"' },
104
- {
105
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
106
- expected: '"setTimeout^(^(^) =^> { console.log^(1, \\"2\'3\\"^); }, 100^)"',
107
- },
108
- {
109
- input: 'console.log("%PATH%")',
110
- expected: '"console.log^(\\"%PATH%\\"^)"',
111
- },
112
- ]
113
- },
114
- },
115
- powershell: {
116
- // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-6
117
- quotingFunctions: PowershellQuotingFunctions,
118
- data: {
119
- [ShellQuoting.Escape]: [
120
- { input: 'abc', expected: 'abc' },
121
- { input: 'ab c', expected: 'ab` c' },
122
- { input: 'ab"c', expected: 'ab`"c' },
123
- { input: 'ab\'c', expected: 'ab`\'c' },
124
- { input: 'ab` c`', expected: 'ab``` c``' },
125
- {
126
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
127
- expected: 'setTimeout`(`(`)` =`>` `{` console.log`(1,` `"2`\'3`"`)`;` `},` 100`)',
128
- },
129
- ],
130
- [ShellQuoting.Strong]: [
131
- { input: 'abc', expected: '\'abc\'' },
132
- { input: 'ab c', expected: '\'ab c\'' },
133
- { input: 'ab"c', expected: '\'ab"c\'' },
134
- { input: 'ab\'c', expected: '\'ab\'\'c\'' },
135
- { input: 'ab` c`', expected: '\'ab` c`\'' },
136
- {
137
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
138
- expected: '\'setTimeout(() => { console.log(1, "2\'\'3"); }, 100)\'',
139
- },
140
- ],
141
- [ShellQuoting.Weak]: [
142
- { input: 'abc', expected: '"abc"' },
143
- { input: 'ab c', expected: '"ab c"' },
144
- { input: 'ab"c', expected: '"ab`"c"' },
145
- { input: 'ab\'c', expected: '"ab\'c"' },
146
- { input: 'ab` c`', expected: '"ab` c``"' },
147
- {
148
- input: 'setTimeout(() => { console.log(1, "2\'3"); }, 100)',
149
- expected: '"setTimeout(() => { console.log(1, `"2\'3`"); }, 100)"',
150
- },
151
- ]
152
- },
153
- }
154
- } as const;
155
-
156
- // Iter through each runtime (bash/cmd/powershell):
157
- for (const runtime of Object.keys(testData)) {
158
- const testInfo = testData[runtime as keyof typeof testData];
159
-
160
- // Get all quoting types (escape/strong/weak):
161
- for (const quotingType of Object.keys(testInfo.data)) {
162
- const testInput = testInfo.data[quotingType as keyof typeof testInfo['data']];
163
-
164
- // Run the test for each input:
165
- it(`${runtime}/${quotingType}`, () => {
166
- for (const test of testInput) {
167
- expect(escapeForShell({
168
- quoting: quotingType as ShellQuoting,
169
- value: test.input,
170
- }, testInfo.quotingFunctions)).equal(test.expected);
171
- }
172
- });
173
- }
174
- }
175
-
176
- });