提交 ea2c961e 编写于 作者: J Johannes Rieken

use `path.win32.*` and `fsPath` when dealing with file-uris on windows,...

use `path.win32.*` and `fsPath` when dealing with file-uris on windows, https://github.com/microsoft/vscode/issues/90208
上级 7a20db3e
......@@ -205,7 +205,7 @@ export class URI implements UriComponents {
// if (this.scheme !== 'file') {
// console.warn(`[UriError] calling fsPath with scheme ${this.scheme}`);
// }
return _makeFsPath(this);
return _makeFsPath(this, false);
}
// ---- modify to new -------------------------
......@@ -347,9 +347,13 @@ export class URI implements UriComponents {
if (!uri.path) {
throw new Error(`[UriError]: cannot call joinPaths on URI without path`);
}
return uri.with({
path: paths.posix.join(uri.path, ...pathFragment)
});
let newPath: string;
if (isWindows && uri.scheme === 'file') {
newPath = URI.file(paths.win32.join(_makeFsPath(uri, true), ...pathFragment)).path;
} else {
newPath = paths.posix.join(uri.path, ...pathFragment);
}
return uri.with({ path: newPath });
}
// ---- printing/externalize ---------------------------
......@@ -416,7 +420,7 @@ class _URI extends URI {
get fsPath(): string {
if (!this._fsPath) {
this._fsPath = _makeFsPath(this);
this._fsPath = _makeFsPath(this, false);
}
return this._fsPath;
}
......@@ -572,7 +576,7 @@ function encodeURIComponentMinimal(path: string): string {
/**
* Compute `fsPath` for the given uri
*/
function _makeFsPath(uri: URI): string {
function _makeFsPath(uri: URI, keepDriveLetterCasing: boolean): string {
let value: string;
if (uri.authority && uri.path.length > 1 && uri.scheme === 'file') {
......@@ -584,7 +588,11 @@ function _makeFsPath(uri: URI): string {
&& uri.path.charCodeAt(2) === CharCode.Colon
) {
// windows drive letter: file:///c:/far/boo
value = uri.path[1].toLowerCase() + uri.path.substr(2);
if (!keepDriveLetterCasing) {
value = uri.path[1].toLowerCase() + uri.path.substr(2);
} else {
value = uri.path.substr(1, 2);
}
} else {
// other path
value = uri.path;
......
......@@ -503,29 +503,22 @@ suite('URI', () => {
// }
// console.profileEnd();
});
test('URI#joinPath', function () {
function assertJoined(base: string, fragment: string, expected: string, checkWithUrl: boolean = true) {
const baseUri = URI.parse(base);
const newUri = URI.joinPath(baseUri, fragment);
const actual = newUri.toString(true);
assert.equal(actual, expected);
if (checkWithUrl) {
const actualUrl = new URL(fragment, base).href;
assert.equal(actualUrl, expected);
}
function assertJoined(base: string, fragment: string, expected: string, checkWithUrl: boolean = true) {
const baseUri = URI.parse(base);
const newUri = URI.joinPath(baseUri, fragment);
const actual = newUri.toString(true);
assert.equal(actual, expected);
if (checkWithUrl) {
const actualUrl = new URL(fragment, base).href;
assert.equal(actualUrl, expected, 'DIFFERENT from URL');
}
}
test('URI#joinPath', function () {
assertJoined(('file://server/share/c:/'), '../../bazz', 'file://server/bazz');
assertJoined(('file://server/share/c:'), '../../bazz', 'file://server/bazz');
assertJoined(('file:///foo/'), '../../bazz', 'file:///bazz');
assertJoined(('file:///foo'), '../../bazz', 'file:///bazz');
assertJoined(('file:///foo'), '../../bazz', 'file:///bazz');
assertJoined(('file:///c:/foo/'), '../../bazz', 'file:///bazz', false);
assertJoined(('file://ser/foo/'), '../../bazz', 'file://ser/bazz');
assertJoined(('file://ser/foo'), '../../bazz', 'file://ser/bazz');
assertJoined(('file:///foo/bar/'), './bazz', 'file:///foo/bar/bazz');
assertJoined(('file:///foo/bar'), './bazz', 'file:///foo/bar/bazz', false);
assertJoined(('file:///foo/bar'), 'bazz', 'file:///foo/bar/bazz', false);
......@@ -547,4 +540,28 @@ suite('URI', () => {
assert.throws(() => assertJoined(('foo://bar'), 'bazz', ''));
assert.throws(() => new URL('bazz', 'foo://bar'));
});
test('URI#joinPath (posix)', function () {
if (isWindows) {
this.skip();
}
assertJoined(('file:///c:/foo/'), '../../bazz', 'file:///bazz', false);
assertJoined(('file://server/share/c:/'), '../../bazz', 'file://server/bazz', false);
assertJoined(('file://server/share/c:'), '../../bazz', 'file://server/bazz', false);
assertJoined(('file://ser/foo/'), '../../bazz', 'file://ser/bazz');
assertJoined(('file://ser/foo'), '../../bazz', 'file://ser/bazz');
});
test('URI#joinPath (windows)', function () {
if (!isWindows) {
this.skip();
}
assertJoined(('file:///c:/foo/'), '../../bazz', 'file:///c:/bazz', false);
assertJoined(('file://server/share/c:/'), '../../bazz', 'file://server/share/bazz', false);
assertJoined(('file://server/share/c:'), '../../bazz', 'file://server/share/bazz', false);
assertJoined(('file://ser/foo/'), '../../bazz', 'file://ser/foo/bazz', false);
assertJoined(('file://ser/foo'), '../../bazz', 'file://ser/foo/bazz', false);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册