From 2d01d1c4b1bce99babd2a7638d00696ed65aa385 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 24 Jan 2018 09:59:25 +0100 Subject: [PATCH] fix #41987 --- src/vs/base/common/resources.ts | 7 ++++++- src/vs/base/test/common/resources.test.ts | 12 +++++++++++- .../browser/parts/quickopen/quickOpenController.ts | 13 +------------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/vs/base/common/resources.ts b/src/vs/base/common/resources.ts index 3012d4a5b159..bbc5c6ca2233 100644 --- a/src/vs/base/common/resources.ts +++ b/src/vs/base/common/resources.ts @@ -38,8 +38,13 @@ export function isEqual(first: uri, second: uri, ignoreCase?: boolean): boolean } export function dirname(resource: uri): uri { + const dirname = paths.dirname(resource.path); + if (resource.authority && dirname && !paths.isAbsolute(dirname)) { + return null; // If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character + } + return resource.with({ - path: paths.dirname(resource.path) + path: dirname }); } diff --git a/src/vs/base/test/common/resources.test.ts b/src/vs/base/test/common/resources.test.ts index f9275777a536..c0940975c3c4 100644 --- a/src/vs/base/test/common/resources.test.ts +++ b/src/vs/base/test/common/resources.test.ts @@ -6,7 +6,7 @@ import * as assert from 'assert'; import URI from 'vs/base/common/uri'; -import { distinctParents } from 'vs/base/common/resources'; +import { distinctParents, dirname } from 'vs/base/common/resources'; suite('Resources', () => { @@ -40,4 +40,14 @@ suite('Resources', () => { assert.equal(distinct[1].toString(), resources[3].toString()); assert.equal(distinct[2].toString(), resources[4].toString()); }); + + test('dirname', (done) => { + const f = URI.file('/some/file/test.txt'); + const d = dirname(f); + assert.equal(d.fsPath, '/some/file'); + + // does not explode (https://github.com/Microsoft/vscode/issues/41987) + URI.from({ scheme: 'file', authority: '/users/someone/portal.h' }); + done(); + }); }); \ No newline at end of file diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 1da92a9404f4..935b7d8bed58 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -55,7 +55,6 @@ import { FileKind, IFileService } from 'vs/platform/files/common/files'; import { scoreItem, ScorerCache, compareItemsByScore, prepareQuery } from 'vs/base/parts/quickopen/common/quickOpenScorer'; import { getBaseLabel } from 'vs/base/common/labels'; import { WorkbenchTree } from 'vs/platform/list/browser/listService'; -import { dirname } from 'vs/base/common/paths'; const HELP_PREFIX = '?'; @@ -1260,7 +1259,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry { const resourceInput = input as IResourceInput; this.resource = resourceInput.resource; this.label = getBaseLabel(resourceInput.resource); - this.description = labels.getPathLabel(this.safeDirname(this.resource), contextService, environmentService); + this.description = labels.getPathLabel(resources.dirname(this.resource), contextService, environmentService); this.dirty = this.resource && this.textFileService.isDirty(this.resource); if (this.dirty && this.textFileService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY) { @@ -1269,16 +1268,6 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry { } } - private safeDirname(resource: URI): string | URI { - try { - return resources.dirname(resource); // workaround for https://github.com/Microsoft/vscode/issues/41987 - } catch (error) { - console.warn(`Unable to resolve to parent resource: ${resource.toString()}`, resource, error); - - return dirname(resource.fsPath); - } - } - public getIcon(): string { return this.dirty ? 'dirty' : ''; }