diff --git a/src/vs/base/common/extpath.ts b/src/vs/base/common/extpath.ts index ae6e731f809f1f545ea7b5de1bff146018372647..20d271c2fcc2377a81a490f9e66efbd2cb393e78 100644 --- a/src/vs/base/common/extpath.ts +++ b/src/vs/base/common/extpath.ts @@ -21,6 +21,15 @@ function _isNormal(path: string, win: boolean): boolean { : !_posixBadPath.test(path); } +/** + * Takes a Windows OS path and changes backward slashes to forward slashes. + * This should only be done for OS paths from Windows (or user provided paths potentially from Windows). + * Using it on a Linux or MaxOS path might change it. + */ +export function toForwardSlashes(osPath: string) { + return osPath.replace(/[\\/]/g, '/'); +} + export function normalize(path: undefined, toOSPath?: boolean): undefined; export function normalize(path: null, toOSPath?: boolean): null; export function normalize(path: string, toOSPath?: boolean): string; diff --git a/src/vs/base/test/common/extpath.test.ts b/src/vs/base/test/common/extpath.test.ts index d324df27eb30b20e3f952329f2e5734961f72881..c97a8bd7ff9499121b604218ebdb30ef30c420d4 100644 --- a/src/vs/base/test/common/extpath.test.ts +++ b/src/vs/base/test/common/extpath.test.ts @@ -8,6 +8,14 @@ import * as platform from 'vs/base/common/platform'; suite('Paths', () => { + test('toForwardSlashes', () => { + assert.equal(extpath.toForwardSlashes('\\\\server\\share\\some\\path'), '//server/share/some/path'); + assert.equal(extpath.toForwardSlashes('c:\\test'), 'c:/test'); + assert.equal(extpath.toForwardSlashes('foo\\bar'), 'foo/bar'); + assert.equal(extpath.toForwardSlashes('/user/far'), '/user/far'); + }); + + test('normalize', () => { assert.equal(extpath.normalize(''), '.'); assert.equal(extpath.normalize('.'), '.'); @@ -54,7 +62,7 @@ suite('Paths', () => { assert.equal(extpath.join('/home/aeschli/workspaces/vscode/extensions/css', './syntaxes/css.plist'), '/home/aeschli/workspaces/vscode/extensions/css/syntaxes/css.plist'); }); - test('getRootLength', () => { + test('getRoot', () => { assert.equal(extpath.getRoot('/user/far'), '/'); assert.equal(extpath.getRoot('\\\\server\\share\\some\\path'), '//server/share/');