Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normallize drive letter to upper case when convert uri to FsPath, fix #155883 #156781

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/vs/base/common/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ export function uriToFsPath(uri: URI, keepDriveLetterCasing: boolean): string {
&& uri.path.charCodeAt(2) === CharCode.Colon
) {
if (!keepDriveLetterCasing) {
// windows drive letter: file:///c:/far/boo
value = uri.path[1].toLowerCase() + uri.path.substr(2);
// windows drive letter: file:///C:/far/boo
value = uri.path[1].toUpperCase() + uri.path.slice(2);
} else {
value = uri.path.substr(1);
value = uri.path.slice(1);
}
} else {
// other path
Expand Down Expand Up @@ -653,16 +653,16 @@ function _asFormatted(uri: URI, skipEncoding: boolean): string {
}
}
if (path) {
// lower-case windows drive letters in /C:/fff or C:/fff
// upper-case windows drive letters in /C:/fff or C:/fff
if (path.length >= 3 && path.charCodeAt(0) === CharCode.Slash && path.charCodeAt(2) === CharCode.Colon) {
const code = path.charCodeAt(1);
if (code >= CharCode.A && code <= CharCode.Z) {
path = `/${String.fromCharCode(code + 32)}:${path.substr(3)}`; // "/c:".length === 3
if (code >= CharCode.a && code <= CharCode.z) {
path = `/${String.fromCharCode(code - 32)}:${path.substr(3)}`; // "/C:".length === 3
}
} else if (path.length >= 2 && path.charCodeAt(1) === CharCode.Colon) {
const code = path.charCodeAt(0);
if (code >= CharCode.A && code <= CharCode.Z) {
path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3
if (code >= CharCode.a && code <= CharCode.z) {
path = `${String.fromCharCode(code - 32)}:${path.substr(2)}`; // "/C:".length === 3
}
}
// encode the rest of the path
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/test/browser/markdownRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ suite('MarkdownRenderer', () => {

test('npm Hover Run Script not working #90855', function () {

const md: IMarkdownString = JSON.parse('{"value":"[Run Script](command:npm.runScriptFromHover?%7B%22documentUri%22%3A%7B%22%24mid%22%3A1%2C%22fsPath%22%3A%22c%3A%5C%5CUsers%5C%5Cjrieken%5C%5CCode%5C%5C_sample%5C%5Cfoo%5C%5Cpackage.json%22%2C%22_sep%22%3A1%2C%22external%22%3A%22file%3A%2F%2F%2Fc%253A%2FUsers%2Fjrieken%2FCode%2F_sample%2Ffoo%2Fpackage.json%22%2C%22path%22%3A%22%2Fc%3A%2FUsers%2Fjrieken%2FCode%2F_sample%2Ffoo%2Fpackage.json%22%2C%22scheme%22%3A%22file%22%7D%2C%22script%22%3A%22echo%22%7D \\"Run the script as a task\\")","supportThemeIcons":false,"isTrusted":true,"uris":{"__uri_e49443":{"$mid":1,"fsPath":"c:\\\\Users\\\\jrieken\\\\Code\\\\_sample\\\\foo\\\\package.json","_sep":1,"external":"file:///c%3A/Users/jrieken/Code/_sample/foo/package.json","path":"/c:/Users/jrieken/Code/_sample/foo/package.json","scheme":"file"},"command:npm.runScriptFromHover?%7B%22documentUri%22%3A%7B%22%24mid%22%3A1%2C%22fsPath%22%3A%22c%3A%5C%5CUsers%5C%5Cjrieken%5C%5CCode%5C%5C_sample%5C%5Cfoo%5C%5Cpackage.json%22%2C%22_sep%22%3A1%2C%22external%22%3A%22file%3A%2F%2F%2Fc%253A%2FUsers%2Fjrieken%2FCode%2F_sample%2Ffoo%2Fpackage.json%22%2C%22path%22%3A%22%2Fc%3A%2FUsers%2Fjrieken%2FCode%2F_sample%2Ffoo%2Fpackage.json%22%2C%22scheme%22%3A%22file%22%7D%2C%22script%22%3A%22echo%22%7D":{"$mid":1,"path":"npm.runScriptFromHover","scheme":"command","query":"{\\"documentUri\\":\\"__uri_e49443\\",\\"script\\":\\"echo\\"}"}}}');
const md: IMarkdownString = JSON.parse('{"value":"[Run Script](command:npm.runScriptFromHover?%7B%22documentUri%22%3A%7B%22%24mid%22%3A1%2C%22fsPath%22%3A%22c%3A%5C%5CUsers%5C%5Cjrieken%5C%5CCode%5C%5C_sample%5C%5Cfoo%5C%5Cpackage.json%22%2C%22_sep%22%3A1%2C%22external%22%3A%22file%3A%2F%2F%2Fc%253A%2FUsers%2Fjrieken%2FCode%2F_sample%2Ffoo%2Fpackage.json%22%2C%22path%22%3A%22%2Fc%3A%2FUsers%2Fjrieken%2FCode%2F_sample%2Ffoo%2Fpackage.json%22%2C%22scheme%22%3A%22file%22%7D%2C%22script%22%3A%22echo%22%7D \\"Run the script as a task\\")","supportThemeIcons":false,"isTrusted":true,"uris":{"__uri_e49443":{"$mid":1,"fsPath":"c:\\\\Users\\\\jrieken\\\\Code\\\\_sample\\\\foo\\\\package.json","_sep":1,"external":"file:///C%3A/Users/jrieken/Code/_sample/foo/package.json","path":"/c:/Users/jrieken/Code/_sample/foo/package.json","scheme":"file"},"command:npm.runScriptFromHover?%7B%22documentUri%22%3A%7B%22%24mid%22%3A1%2C%22fsPath%22%3A%22c%3A%5C%5CUsers%5C%5Cjrieken%5C%5CCode%5C%5C_sample%5C%5Cfoo%5C%5Cpackage.json%22%2C%22_sep%22%3A1%2C%22external%22%3A%22file%3A%2F%2F%2Fc%253A%2FUsers%2Fjrieken%2FCode%2F_sample%2Ffoo%2Fpackage.json%22%2C%22path%22%3A%22%2Fc%3A%2FUsers%2Fjrieken%2FCode%2F_sample%2Ffoo%2Fpackage.json%22%2C%22scheme%22%3A%22file%22%7D%2C%22script%22%3A%22echo%22%7D":{"$mid":1,"path":"npm.runScriptFromHover","scheme":"command","query":"{\\"documentUri\\":\\"__uri_e49443\\",\\"script\\":\\"echo\\"}"}}}');
const element = renderMarkdown(md).element;

const anchor = element.querySelector('a')!;
Expand All @@ -216,7 +216,7 @@ suite('MarkdownRenderer', () => {
const data = <{ script: string; documentUri: URI }>parse(decodeURIComponent(uri.query));
assert.ok(data);
assert.strictEqual(data.script, 'echo');
assert.ok(data.documentUri.toString().startsWith('file:///c%3A/'));
assert.ok(data.documentUri.toString().startsWith('file:///C%3A/'));
});

test('Should not render command links by default', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/base/test/common/console.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ suite('Console', () => {
assert.strictEqual(frame.line, 18);
assert.strictEqual(frame.column, 17);

stack = 'at c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17';
stack = 'at C:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17';
frame = getFirstFrame(stack)!;

assert.strictEqual(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
assert.strictEqual(frame.uri.fsPath, 'C:\\Users\\someone\\Desktop\\end-js\\extension.js');
assert.strictEqual(frame.line, 18);
assert.strictEqual(frame.column, 17);

stack = 'at e.$executeContributedCommand(c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17)';
stack = 'at e.$executeContributedCommand(C:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17)';
frame = getFirstFrame(stack)!;

assert.strictEqual(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
assert.strictEqual(frame.uri.fsPath, 'C:\\Users\\someone\\Desktop\\end-js\\extension.js');
assert.strictEqual(frame.line, 18);
assert.strictEqual(frame.column, 17);

Expand Down
26 changes: 18 additions & 8 deletions src/vs/base/test/common/labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,24 @@ suite('Labels', () => {
});

test('getPathLabel', () => {
const winFileUri = URI.file('c:/some/folder/file.txt');
const winFileUri = URI.file('C:/some/folder/file.txt');
const nixFileUri = URI.file('/some/folder/file.txt');
const uncFileUri = URI.file('c:/some/folder/file.txt').with({ authority: 'auth' });
const uncFileUri = URI.file('C:/some/folder/file.txt').with({ authority: 'auth' });
const remoteFileUri = URI.file('/some/folder/file.txt').with({ scheme: 'vscode-test', authority: 'auth' });

// Basics

assert.strictEqual(labels.getPathLabel(winFileUri, { os: OperatingSystem.Windows }), 'C:\\some\\folder\\file.txt');
assert.strictEqual(labels.getPathLabel(winFileUri, { os: OperatingSystem.Macintosh }), 'c:/some/folder/file.txt');
assert.strictEqual(labels.getPathLabel(winFileUri, { os: OperatingSystem.Linux }), 'c:/some/folder/file.txt');
assert.strictEqual(labels.getPathLabel(winFileUri, { os: OperatingSystem.Macintosh }), 'C:/some/folder/file.txt');
assert.strictEqual(labels.getPathLabel(winFileUri, { os: OperatingSystem.Linux }), 'C:/some/folder/file.txt');

assert.strictEqual(labels.getPathLabel(nixFileUri, { os: OperatingSystem.Windows }), '\\some\\folder\\file.txt');
assert.strictEqual(labels.getPathLabel(nixFileUri, { os: OperatingSystem.Macintosh }), '/some/folder/file.txt');
assert.strictEqual(labels.getPathLabel(nixFileUri, { os: OperatingSystem.Linux }), '/some/folder/file.txt');

assert.strictEqual(labels.getPathLabel(uncFileUri, { os: OperatingSystem.Windows }), '\\\\auth\\c:\\some\\folder\\file.txt');
assert.strictEqual(labels.getPathLabel(uncFileUri, { os: OperatingSystem.Macintosh }), '/auth/c:/some/folder/file.txt');
assert.strictEqual(labels.getPathLabel(uncFileUri, { os: OperatingSystem.Linux }), '/auth/c:/some/folder/file.txt');
assert.strictEqual(labels.getPathLabel(uncFileUri, { os: OperatingSystem.Windows }), '\\\\auth\\C:\\some\\folder\\file.txt');
assert.strictEqual(labels.getPathLabel(uncFileUri, { os: OperatingSystem.Macintosh }), '/auth/C:/some/folder/file.txt');
assert.strictEqual(labels.getPathLabel(uncFileUri, { os: OperatingSystem.Linux }), '/auth/C:/some/folder/file.txt');

assert.strictEqual(labels.getPathLabel(remoteFileUri, { os: OperatingSystem.Windows }), '\\some\\folder\\file.txt');
assert.strictEqual(labels.getPathLabel(remoteFileUri, { os: OperatingSystem.Macintosh }), '/some/folder/file.txt');
Expand Down Expand Up @@ -203,7 +203,7 @@ suite('Labels', () => {

// Relative

const winFolder = URI.file('c:/some');
const winFolder = URI.file('C:/some');
const winRelativePathProvider: labels.IRelativePathProvider = {
getWorkspace() { return { folders: [{ uri: winFolder }] }; },
getWorkspaceFolder(resource) { return { uri: winFolder }; }
Expand All @@ -227,4 +227,14 @@ suite('Labels', () => {
assert.strictEqual(labels.getPathLabel(nixUntitledUri, { os: OperatingSystem.Macintosh, relative: nixRelativePathProvider }), 'folder/file.txt');
assert.strictEqual(labels.getPathLabel(nixUntitledUri, { os: OperatingSystem.Linux, relative: nixRelativePathProvider }), 'folder/file.txt');
});

test('winDiskLetter', () => {
const winFileUri = URI.file('c:/some/folder/file.txt');


assert.strictEqual(labels.getPathLabel(winFileUri, { os: OperatingSystem.Windows }), 'C:\\some\\folder\\file.txt');
assert.strictEqual(labels.getPathLabel(winFileUri, { os: OperatingSystem.Macintosh }), 'C:/some/folder/file.txt');
assert.strictEqual(labels.getPathLabel(winFileUri, { os: OperatingSystem.Linux }), 'C:/some/folder/file.txt');
});

});
48 changes: 24 additions & 24 deletions src/vs/base/test/common/resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ suite('Resources', () => {

test('dirname', () => {
if (isWindows) {
assert.strictEqual(dirname(URI.file('c:\\some\\file\\test.txt')).toString(), 'file:///c%3A/some/file');
assert.strictEqual(dirname(URI.file('c:\\some\\file')).toString(), 'file:///c%3A/some');
assert.strictEqual(dirname(URI.file('c:\\some\\file\\')).toString(), 'file:///c%3A/some');
assert.strictEqual(dirname(URI.file('c:\\some')).toString(), 'file:///c%3A/');
assert.strictEqual(dirname(URI.file('C:\\some')).toString(), 'file:///c%3A/');
assert.strictEqual(dirname(URI.file('c:\\')).toString(), 'file:///c%3A/');
assert.strictEqual(dirname(URI.file('c:\\some\\file\\test.txt')).toString(), 'file:///C%3A/some/file');
assert.strictEqual(dirname(URI.file('c:\\some\\file')).toString(), 'file:///C%3A/some');
assert.strictEqual(dirname(URI.file('c:\\some\\file\\')).toString(), 'file:///C%3A/some');
assert.strictEqual(dirname(URI.file('c:\\some')).toString(), 'file:///C%3A/');
assert.strictEqual(dirname(URI.file('C:\\some')).toString(), 'file:///C%3A/');
assert.strictEqual(dirname(URI.file('c:\\')).toString(), 'file:///C%3A/');
} else {
assert.strictEqual(dirname(URI.file('/some/file/test.txt')).toString(), 'file:///some/file');
assert.strictEqual(dirname(URI.file('/some/file/')).toString(), 'file:///some');
Expand Down Expand Up @@ -91,15 +91,15 @@ suite('Resources', () => {

test('joinPath', () => {
if (isWindows) {
assert.strictEqual(joinPath(URI.file('c:\\foo\\bar'), '/file.js').toString(), 'file:///c%3A/foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo\\bar\\'), 'file.js').toString(), 'file:///c%3A/foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo\\bar\\'), '/file.js').toString(), 'file:///c%3A/foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\'), '/file.js').toString(), 'file:///c%3A/file.js');
assert.strictEqual(joinPath(URI.file('c:\\'), 'bar/file.js').toString(), 'file:///c%3A/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo'), './file.js').toString(), 'file:///c%3A/foo/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo'), '/./file.js').toString(), 'file:///c%3A/foo/file.js');
assert.strictEqual(joinPath(URI.file('C:\\foo'), '../file.js').toString(), 'file:///c%3A/file.js');
assert.strictEqual(joinPath(URI.file('C:\\foo\\.'), '../file.js').toString(), 'file:///c%3A/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo\\bar'), '/file.js').toString(), 'file:///C%3A/foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo\\bar\\'), 'file.js').toString(), 'file:///C%3A/foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo\\bar\\'), '/file.js').toString(), 'file:///C%3A/foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\'), '/file.js').toString(), 'file:///C%3A/file.js');
assert.strictEqual(joinPath(URI.file('c:\\'), 'bar/file.js').toString(), 'file:///C%3A/bar/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo'), './file.js').toString(), 'file:///C%3A/foo/file.js');
assert.strictEqual(joinPath(URI.file('c:\\foo'), '/./file.js').toString(), 'file:///C%3A/foo/file.js');
assert.strictEqual(joinPath(URI.file('C:\\foo'), '../file.js').toString(), 'file:///C%3A/file.js');
assert.strictEqual(joinPath(URI.file('C:\\foo\\.'), '../file.js').toString(), 'file:///C%3A/file.js');
} else {
assert.strictEqual(joinPath(URI.file('/foo/bar'), '/file.js').toString(), 'file:///foo/bar/file.js');
assert.strictEqual(joinPath(URI.file('/foo/bar'), 'file.js').toString(), 'file:///foo/bar/file.js');
Expand All @@ -125,15 +125,15 @@ suite('Resources', () => {

test('normalizePath', () => {
if (isWindows) {
assert.strictEqual(normalizePath(URI.file('c:\\foo\\.\\bar')).toString(), 'file:///c%3A/foo/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\.')).toString(), 'file:///c%3A/foo');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\.\\')).toString(), 'file:///c%3A/foo/');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\..')).toString(), 'file:///c%3A/');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\..\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\foo\\..\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.strictEqual(normalizePath(URI.file('C:\\foo\\foo\\.\\..\\..\\bar')).toString(), 'file:///c%3A/bar');
assert.strictEqual(normalizePath(URI.file('C:\\foo\\foo\\.\\..\\some\\..\\bar')).toString(), 'file:///c%3A/foo/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\.\\bar')).toString(), 'file:///C%3A/foo/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\.')).toString(), 'file:///C%3A/foo');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\.\\')).toString(), 'file:///C%3A/foo/');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\..')).toString(), 'file:///C%3A/');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\..\\bar')).toString(), 'file:///C%3A/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\..\\..\\bar')).toString(), 'file:///C%3A/bar');
assert.strictEqual(normalizePath(URI.file('c:\\foo\\foo\\..\\..\\bar')).toString(), 'file:///C%3A/bar');
assert.strictEqual(normalizePath(URI.file('C:\\foo\\foo\\.\\..\\..\\bar')).toString(), 'file:///C%3A/bar');
assert.strictEqual(normalizePath(URI.file('C:\\foo\\foo\\.\\..\\some\\..\\bar')).toString(), 'file:///C%3A/foo/bar');
} else {
assert.strictEqual(normalizePath(URI.file('/foo/./bar')).toString(), 'file:///foo/bar');
assert.strictEqual(normalizePath(URI.file('/foo/.')).toString(), 'file:///foo');
Expand Down
Loading