1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | var assert = require("assert");
|
8 | var windowsPtyAgent_1 = require("./windowsPtyAgent");
|
9 | function check(file, args, expected) {
|
10 | assert.equal(windowsPtyAgent_1.argsToCommandLine(file, args), expected);
|
11 | }
|
12 | if (process.platform === 'win32') {
|
13 | describe('argsToCommandLine', function () {
|
14 | describe('Plain strings', function () {
|
15 | it('doesn\'t quote plain string', function () {
|
16 | check('asdf', [], 'asdf');
|
17 | });
|
18 | it('doesn\'t escape backslashes', function () {
|
19 | check('\\asdf\\qwer\\', [], '\\asdf\\qwer\\');
|
20 | });
|
21 | it('doesn\'t escape multiple backslashes', function () {
|
22 | check('asdf\\\\qwer', [], 'asdf\\\\qwer');
|
23 | });
|
24 | it('adds backslashes before quotes', function () {
|
25 | check('"asdf"qwer"', [], '\\"asdf\\"qwer\\"');
|
26 | });
|
27 | it('escapes backslashes before quotes', function () {
|
28 | check('asdf\\"qwer', [], 'asdf\\\\\\"qwer');
|
29 | });
|
30 | });
|
31 | describe('Quoted strings', function () {
|
32 | it('quotes string with spaces', function () {
|
33 | check('asdf qwer', [], '"asdf qwer"');
|
34 | });
|
35 | it('quotes empty string', function () {
|
36 | check('', [], '""');
|
37 | });
|
38 | it('quotes string with tabs', function () {
|
39 | check('asdf\tqwer', [], '"asdf\tqwer"');
|
40 | });
|
41 | it('escapes only the last backslash', function () {
|
42 | check('\\asdf \\qwer\\', [], '"\\asdf \\qwer\\\\"');
|
43 | });
|
44 | it('doesn\'t escape multiple backslashes', function () {
|
45 | check('asdf \\\\qwer', [], '"asdf \\\\qwer"');
|
46 | });
|
47 | it('escapes backslashes before quotes', function () {
|
48 | check('asdf \\"qwer', [], '"asdf \\\\\\"qwer"');
|
49 | });
|
50 | it('escapes multiple backslashes at the end', function () {
|
51 | check('asdf qwer\\\\', [], '"asdf qwer\\\\\\\\"');
|
52 | });
|
53 | });
|
54 | describe('Multiple arguments', function () {
|
55 | it('joins arguments with spaces', function () {
|
56 | check('asdf', ['qwer zxcv', '', '"'], 'asdf "qwer zxcv" "" \\"');
|
57 | });
|
58 | it('array argument all in quotes', function () {
|
59 | check('asdf', ['"surounded by quotes"'], 'asdf \\"surounded by quotes\\"');
|
60 | });
|
61 | it('array argument quotes in the middle', function () {
|
62 | check('asdf', ['quotes "in the" middle'], 'asdf "quotes \\"in the\\" middle"');
|
63 | });
|
64 | it('array argument quotes near start', function () {
|
65 | check('asdf', ['"quotes" near start'], 'asdf "\\"quotes\\" near start"');
|
66 | });
|
67 | it('array argument quotes near end', function () {
|
68 | check('asdf', ['quotes "near end"'], 'asdf "quotes \\"near end\\""');
|
69 | });
|
70 | });
|
71 | describe('Args as CommandLine', function () {
|
72 | it('should handle empty string', function () {
|
73 | check('file', '', 'file');
|
74 | });
|
75 | it('should not change args', function () {
|
76 | check('file', 'foo bar baz', 'file foo bar baz');
|
77 | check('file', 'foo \\ba"r \baz', 'file foo \\ba"r \baz');
|
78 | });
|
79 | });
|
80 | describe('Real-world cases', function () {
|
81 | it('quotes within quotes', function () {
|
82 | check('cmd.exe', ['/c', 'powershell -noexit -command \'Set-location \"C:\\user\"\''], 'cmd.exe /c "powershell -noexit -command \'Set-location \\\"C:\\user\\"\'"');
|
83 | });
|
84 | it('space within quotes', function () {
|
85 | check('cmd.exe', ['/k', '"C:\\Users\\alros\\Desktop\\test script.bat"'], 'cmd.exe /k \\"C:\\Users\\alros\\Desktop\\test script.bat\\"');
|
86 | });
|
87 | });
|
88 | });
|
89 | }
|
90 |
|
\ | No newline at end of file |