提交 33ef6896 编写于 作者: M Martin Aeschlimann

extpath: new API toForwardSlashes

上级 96e5c7d1
......@@ -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;
......
......@@ -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/');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册