Skip to content

Commit 33ef689

Browse files
committed
extpath: new API toForwardSlashes
1 parent 96e5c7d commit 33ef689

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/vs/base/common/extpath.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ function _isNormal(path: string, win: boolean): boolean {
2121
: !_posixBadPath.test(path);
2222
}
2323

24+
/**
25+
* Takes a Windows OS path and changes backward slashes to forward slashes.
26+
* This should only be done for OS paths from Windows (or user provided paths potentially from Windows).
27+
* Using it on a Linux or MaxOS path might change it.
28+
*/
29+
export function toForwardSlashes(osPath: string) {
30+
return osPath.replace(/[\\/]/g, '/');
31+
}
32+
2433
export function normalize(path: undefined, toOSPath?: boolean): undefined;
2534
export function normalize(path: null, toOSPath?: boolean): null;
2635
export function normalize(path: string, toOSPath?: boolean): string;

src/vs/base/test/common/extpath.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import * as platform from 'vs/base/common/platform';
88

99
suite('Paths', () => {
1010

11+
test('toForwardSlashes', () => {
12+
assert.equal(extpath.toForwardSlashes('\\\\server\\share\\some\\path'), '//server/share/some/path');
13+
assert.equal(extpath.toForwardSlashes('c:\\test'), 'c:/test');
14+
assert.equal(extpath.toForwardSlashes('foo\\bar'), 'foo/bar');
15+
assert.equal(extpath.toForwardSlashes('/user/far'), '/user/far');
16+
});
17+
18+
1119
test('normalize', () => {
1220
assert.equal(extpath.normalize(''), '.');
1321
assert.equal(extpath.normalize('.'), '.');
@@ -54,7 +62,7 @@ suite('Paths', () => {
5462
assert.equal(extpath.join('/home/aeschli/workspaces/vscode/extensions/css', './syntaxes/css.plist'), '/home/aeschli/workspaces/vscode/extensions/css/syntaxes/css.plist');
5563
});
5664

57-
test('getRootLength', () => {
65+
test('getRoot', () => {
5866

5967
assert.equal(extpath.getRoot('/user/far'), '/');
6068
assert.equal(extpath.getRoot('\\\\server\\share\\some\\path'), '//server/share/');

0 commit comments

Comments
 (0)