From 253434c87c55d62a109887aeccc0d0f201739e88 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 18 Jan 2018 17:20:46 -0800 Subject: [PATCH] Fix webview protocol logic for windows Fixes #41795 Make sure we use the correct path seps and normalization on windows for the new webview protocol --- .../workbench/parts/extensions/browser/extensionEditor.ts | 3 ++- src/vs/workbench/parts/html/browser/webview.ts | 7 ++++--- .../parts/update/electron-browser/releaseNotesEditor.ts | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/parts/extensions/browser/extensionEditor.ts b/src/vs/workbench/parts/extensions/browser/extensionEditor.ts index 43a5d963e96..fd380543ec4 100644 --- a/src/vs/workbench/parts/extensions/browser/extensionEditor.ts +++ b/src/vs/workbench/parts/extensions/browser/extensionEditor.ts @@ -53,6 +53,7 @@ import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRe import { Color } from 'vs/base/common/color'; import { WorkbenchTree, IListService } from 'vs/platform/list/browser/listService'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import URI from 'vs/base/common/uri'; /** A context key that is set when an extension editor webview has focus. */ export const KEYBINDING_CONTEXT_EXTENSIONEDITOR_WEBVIEW_FOCUS = new RawContextKey('extensionEditorWebviewFocus', undefined); @@ -67,7 +68,7 @@ function renderBody( body: string, environmentService: IEnvironmentService ): string { - const styleSheetPath = require.toUrl('./media/markdown.css').replace('file://' + environmentService.appRoot, 'vscode-core-resource://'); + const styleSheetPath = require.toUrl('./media/markdown.css').replace(URI.file(environmentService.appRoot).toString(true), 'vscode-core-resource://'); return ` diff --git a/src/vs/workbench/parts/html/browser/webview.ts b/src/vs/workbench/parts/html/browser/webview.ts index b46ee754598..3de46823520 100644 --- a/src/vs/workbench/parts/html/browser/webview.ts +++ b/src/vs/workbench/parts/html/browser/webview.ts @@ -15,7 +15,7 @@ import { WebviewFindWidget } from './webviewFindWidget'; import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; import { IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { normalize, join } from 'vs/base/common/paths'; +import { normalize, join, nativeSep } from 'vs/base/common/paths'; import { startsWith } from 'vs/base/common/strings'; export interface WebviewElementFindInPageOptions { @@ -102,7 +102,7 @@ export default class Webview { const contents = this._webview.getWebContents(); if (contents && !contents.isDestroyed()) { - registerFileProtocol(contents, 'vscode-core-resource', this._environmentService.appRoot); + registerFileProtocol(contents, 'vscode-core-resource', this._environmentService.appRoot + nativeSep); } })); } @@ -421,7 +421,8 @@ function registerFileProtocol( ) { contents.session.protocol.registerFileProtocol(protocol, (request, callback: any) => { const requestPath = URI.parse(request.url).path; - const normalizedPath = normalize(join(root, requestPath)); + const normalizedPath = normalize(join(root, requestPath), true); + console.log(root, requestPath, normalizedPath); if (startsWith(normalizedPath, root)) { callback({ path: normalizedPath }); } else { diff --git a/src/vs/workbench/parts/update/electron-browser/releaseNotesEditor.ts b/src/vs/workbench/parts/update/electron-browser/releaseNotesEditor.ts index 53e1440adbd..444c67aa91f 100644 --- a/src/vs/workbench/parts/update/electron-browser/releaseNotesEditor.ts +++ b/src/vs/workbench/parts/update/electron-browser/releaseNotesEditor.ts @@ -28,13 +28,14 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' import { onUnexpectedError } from 'vs/base/common/errors'; import { addGAParameters } from 'vs/platform/telemetry/node/telemetryNodeUtils'; import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization'; +import URI from 'vs/base/common/uri'; function renderBody( body: string, css: string, environmentService: IEnvironmentService ): string { - const styleSheetPath = require.toUrl('./media/markdown.css').replace('file://' + environmentService.appRoot, 'vscode-core-resource://'); + const styleSheetPath = require.toUrl('./media/markdown.css').replace(URI.file(environmentService.appRoot).toString(true), 'vscode-core-resource://'); return ` -- GitLab