|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 | 6 | import { Terminal } from 'xterm';
|
7 |
| -import { strictEqual } from 'assert'; |
| 7 | +import { strictEqual, deepStrictEqual } from 'assert'; |
8 | 8 | import { timeout } from 'vs/base/common/async';
|
9 | 9 | import * as sinon from 'sinon';
|
10 | 10 | import { ShellIntegrationAddon } from 'vs/platform/terminal/common/xterm/shellIntegrationAddon';
|
@@ -64,6 +64,55 @@ suite('ShellIntegrationAddon', () => {
|
64 | 64 | await writeP(xterm, '\x1b]633;P;Cwd=/foo\x07');
|
65 | 65 | mock.verify();
|
66 | 66 | });
|
| 67 | + |
| 68 | + suite('detect `OSC 7; scheme://cwd ST`', async () => { |
| 69 | + suite('should extract CWD from URL format', async () => { |
| 70 | + test('should accept well-formatted URLs', async () => { |
| 71 | + type TestCase = [title: string, input: string, expected: string]; |
| 72 | + const cases: TestCase[] = [ |
| 73 | + // Different hostname values: |
| 74 | + ['empty hostname, pointing root', 'file:///', '/'], |
| 75 | + ['empty hostname', 'file:///test-root/local', '/test-root/local'], |
| 76 | + ['non-empty hostname', 'file://some-hostname/test-root/local', '/test-root/local'], |
| 77 | + // URL-encoded chars: |
| 78 | + ['URL-encoded value (1)', 'file:///test-root/%6c%6f%63%61%6c', '/test-root/local'], |
| 79 | + ['URL-encoded value (2)', 'file:///test-root/local%22', '/test-root/local"'], |
| 80 | + ['URL-encoded value (3)', 'file:///test-root/local"', '/test-root/local"'], |
| 81 | + ]; |
| 82 | + for (const x of cases) { |
| 83 | + const [title, input, expected] = x; |
| 84 | + const mock = shellIntegrationAddon.getCwdDectionMock(); |
| 85 | + mock.expects('updateCwd').once().withExactArgs(expected).named(title); |
| 86 | + await writeP(xterm, `\x1b]7;${input}\x07`); |
| 87 | + mock.verify(); |
| 88 | + } |
| 89 | + }); |
| 90 | + |
| 91 | + test('should ignore ill-formatted URLs', async () => { |
| 92 | + type TestCase = [title: string, input: string]; |
| 93 | + const cases: TestCase[] = [ |
| 94 | + // Different hostname values: |
| 95 | + ['no hostname, pointing root', 'file://'], |
| 96 | + // Non-`file` scheme values: |
| 97 | + ['no scheme (1)', '/test-root'], |
| 98 | + ['no scheme (2)', '//test-root'], |
| 99 | + ['no scheme (3)', '///test-root'], |
| 100 | + ['no scheme (4)', ':///test-root'], |
| 101 | + ['http', 'http:///test-root'], |
| 102 | + ['ftp', 'ftp:///test-root'], |
| 103 | + ['ssh', 'ssh:///test-root'], |
| 104 | + ]; |
| 105 | + |
| 106 | + for (const x of cases) { |
| 107 | + const [title, input] = x; |
| 108 | + const mock = shellIntegrationAddon.getCwdDectionMock(); |
| 109 | + mock.expects('updateCwd').never().named(title); |
| 110 | + await writeP(xterm, `\x1b]7;${input}\x07`); |
| 111 | + mock.verify(); |
| 112 | + } |
| 113 | + }); |
| 114 | + }); |
| 115 | + }); |
67 | 116 | });
|
68 | 117 |
|
69 | 118 | suite('command tracking', async () => {
|
|
0 commit comments