Skip to content

Commit dbc8da9

Browse files
committed
src/goDebug: fix drive casing when substituting paths
Due to microsoft/vscode#9448 (comment) the drive casing may not be correct for filepaths on windows. This change makes sure to capitalize the drive name for the paths to be substituted. Although the local machine may not be windows, the remote machine may be, so we check for the drive name on all paths. Change-Id: I7993f6426f1d25d490b655c38598ab977acf774f Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/277963 Trust: Suzy Mueller <suzmue@golang.org> Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Suzy Mueller <suzmue@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
1 parent 2f72921 commit dbc8da9

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

src/debugAdapter/goDebug.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,18 @@ function normalizePath(filePath: string) {
371371
return filePath;
372372
}
373373

374-
function normalizeSeparators(filePath: string): string {
374+
// normalizeSeparators will prepare the filepath for comparison in mapping from
375+
// local to debugger path and from debugger path to local path. All separators are
376+
// replaced with '/', and the drive name is capitalized for windows paths.
377+
// Exported for testing
378+
export function normalizeSeparators(filePath: string): string {
379+
// Although the current machine may not be running windows,
380+
// the remote machine may be and we need to fix the drive
381+
// casing.
382+
// This is a workaround for issue in https://github.com/Microsoft/vscode/issues/9448#issuecomment-244804026
383+
if (filePath.indexOf(':') === 1) {
384+
filePath = filePath.substr(0, 1).toUpperCase() + filePath.substr(1);
385+
}
375386
return filePath.replace(/\/|\\/g, '/');
376387
}
377388

test/unit/goDebug.test.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE in the project root for license information.
4+
*--------------------------------------------------------*/
5+
6+
import * as assert from 'assert';
7+
import { normalizeSeparators } from '../../src/debugAdapter/goDebug';
8+
9+
suite('NormalizeSeparators Tests', () => {
10+
test('fix separator', () => {
11+
const tt = [
12+
{
13+
input: 'path/to/file',
14+
want: 'path/to/file',
15+
},
16+
{
17+
input: '\\path\\to\\file',
18+
want: '/path/to/file',
19+
},
20+
{
21+
input: '/path/to\\file',
22+
want: '/path/to/file',
23+
},
24+
];
25+
26+
for (const tc of tt) {
27+
const got = normalizeSeparators(tc.input);
28+
assert.strictEqual(got, tc.want);
29+
}
30+
});
31+
test('fix drive casing', () => {
32+
const tt = [
33+
{
34+
input: 'C:/path/to/file',
35+
want: 'C:/path/to/file',
36+
},
37+
{
38+
input: 'c:/path/to/file',
39+
want: 'C:/path/to/file',
40+
},
41+
{
42+
input: 'C:/path/to/file',
43+
want: 'C:/path/to/file',
44+
},
45+
{
46+
input: 'C:\\path\\to\\file',
47+
want: 'C:/path/to/file',
48+
},
49+
{
50+
input: 'c:\\path\\to\\file',
51+
want: 'C:/path/to/file',
52+
},
53+
{
54+
input: 'c:\\path\\to\\file',
55+
want: 'C:/path/to/file',
56+
}
57+
];
58+
59+
for (const tc of tt) {
60+
const got = normalizeSeparators(tc.input);
61+
assert.strictEqual(got, tc.want);
62+
}
63+
});
64+
test('relative paths', () => {
65+
const tt = [
66+
{
67+
input: '../path/to/file',
68+
want: '../path/to/file',
69+
},
70+
{
71+
input: './path/to/file',
72+
want: './path/to/file',
73+
},
74+
{
75+
input: '..\\path\\to\\file',
76+
want: '../path/to/file',
77+
},
78+
{
79+
input: '.\\path\\to\\file',
80+
want: './path/to/file',
81+
},
82+
{
83+
input: '/path/to/../file',
84+
want: '/path/to/../file',
85+
},
86+
{
87+
input: 'c:\\path\\to\\..\\file',
88+
want: 'C:/path/to/../file',
89+
}
90+
];
91+
92+
for (const tc of tt) {
93+
const got = normalizeSeparators(tc.input);
94+
assert.strictEqual(got, tc.want);
95+
}
96+
});
97+
98+
});

0 commit comments

Comments
 (0)