From af5dd228ed306861d4768d9772184aedc0cd510b Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 16 Sep 2020 19:49:14 -0700 Subject: [PATCH] Make sure we create a unique working copy resource for each custom editor resource Fixes #106547 This switching the working copy resource for custom editors to use an encoded path instead of the resource's original path. This fixes a few problems: - Fixes a bug where two resources with the same path (but different schemes or authorities) would be considered the same - Fixes a bug where windows style paths (`c:\path`) would cause issues. This is the root cause of #106547 - Fixes a bug where the viewType was used as the raw authority. If the view type contains invalid characters, this would have caused issues --- src/vs/workbench/api/browser/mainThreadCustomEditors.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadCustomEditors.ts b/src/vs/workbench/api/browser/mainThreadCustomEditors.ts index ca957970aa8e9..287272269322a 100644 --- a/src/vs/workbench/api/browser/mainThreadCustomEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadCustomEditors.ts @@ -346,10 +346,12 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod } private static toWorkingCopyResource(viewType: string, resource: URI) { + const authority = viewType.replace(/[^a-z0-9\-_]/gi, '-'); + const path = '/' + btoa(resource.with({ query: null, fragment: null }).toString(true)); return URI.from({ scheme: Schemas.vscodeCustomEditor, - authority: viewType, - path: resource.path, + authority: authority, + path: path, query: JSON.stringify(resource.toJSON()), }); }