Skip to content

Commit 515c6c2

Browse files
committed
⚗️ Add tests to verify handling sequence: OSC 7; scheme://cwd ST
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent 0298970 commit 515c6c2

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/vs/workbench/contrib/terminal/test/browser/xterm/shellIntegrationAddon.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Terminal } from 'xterm';
7-
import { strictEqual } from 'assert';
7+
import { strictEqual, deepStrictEqual } from 'assert';
88
import { timeout } from 'vs/base/common/async';
99
import * as sinon from 'sinon';
1010
import { ShellIntegrationAddon } from 'vs/platform/terminal/common/xterm/shellIntegrationAddon';
@@ -64,6 +64,55 @@ suite('ShellIntegrationAddon', () => {
6464
await writeP(xterm, '\x1b]633;P;Cwd=/foo\x07');
6565
mock.verify();
6666
});
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+
});
67116
});
68117

69118
suite('command tracking', async () => {

0 commit comments

Comments
 (0)