Skip to content

Commit 64592bc

Browse files
committed
src/debugAdapter: default path separator to '/'
The path separator '/' is accepted by delve for filepaths, even on windows, but '\\' is not. Therefore we should default to using '/'. Updates #1497 Change-Id: If3df8e9a9f05f1b103ee1a361e353f776a057343 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/319350 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent a2c2efc commit 64592bc

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/debugAdapter/goDebug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ function logError(...args: any[]) {
356356
logger.error(logArgsToString(args));
357357
}
358358

359-
function findPathSeparator(filePath: string) {
360-
return filePath.includes('/') ? '/' : '\\';
359+
export function findPathSeparator(filePath: string) {
360+
return filePath.includes('\\') ? '\\' : '/';
361361
}
362362

363363
// Comparing two different file paths while ignoring any different path separators.

test/unit/goDebug.test.ts

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

66
import * as assert from 'assert';
7-
import { normalizeSeparators } from '../../src/debugAdapter/goDebug';
7+
import { findPathSeparator, normalizeSeparators } from '../../src/debugAdapter/goDebug';
88

99
suite('NormalizeSeparators Tests', () => {
1010
test('fix separator', () => {
@@ -94,4 +94,42 @@ suite('NormalizeSeparators Tests', () => {
9494
assert.strictEqual(got, tc.want);
9595
}
9696
});
97+
98+
test('find path separator', () => {
99+
const tt = [
100+
{
101+
input: '../path/to/file',
102+
want: '/'
103+
},
104+
{
105+
input: './path/to/file',
106+
want: '/'
107+
},
108+
{
109+
input: '..\\path\\to\\file',
110+
want: '\\'
111+
},
112+
{
113+
input: '.\\path\\to\\file',
114+
want: '\\'
115+
},
116+
{
117+
input: '/path/to/../file',
118+
want: '/'
119+
},
120+
{
121+
input: 'c:\\path\\to\\..\\file',
122+
want: '\\'
123+
},
124+
{
125+
input: '',
126+
want: '/'
127+
}
128+
];
129+
130+
for (const tc of tt) {
131+
const got = findPathSeparator(tc.input);
132+
assert.strictEqual(got, tc.want);
133+
}
134+
});
97135
});

0 commit comments

Comments
 (0)