From 54fb49cdc53d5862b2a9d638c52acdd2624a6fcb Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 12 Nov 2018 15:11:34 -0800 Subject: [PATCH] Don't take user file associations into account for webview mime types Fixes #62892 --- src/vs/base/common/mime.ts | 12 +++++++----- .../webview/electron-browser/webviewProtocols.ts | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/vs/base/common/mime.ts b/src/vs/base/common/mime.ts index 507067b2649..d7777d9dd13 100644 --- a/src/vs/base/common/mime.ts +++ b/src/vs/base/common/mime.ts @@ -106,7 +106,7 @@ export function clearTextMimes(onlyUserConfigured?: boolean): void { /** * Given a file, return the best matching mime type for it */ -export function guessMimeTypes(path: string, firstLine?: string): string[] { +export function guessMimeTypes(path: string, firstLine?: string, skipUserAssociations: boolean = false): string[] { if (!path) { return [MIME_UNKNOWN]; } @@ -114,10 +114,12 @@ export function guessMimeTypes(path: string, firstLine?: string): string[] { path = path.toLowerCase(); const filename = paths.basename(path); - // 1.) User configured mappings have highest priority - const configuredMime = guessMimeTypeByPath(path, filename, userRegisteredAssociations); - if (configuredMime) { - return [configuredMime, MIME_TEXT]; + if (!skipUserAssociations) { + // 1.) User configured mappings have highest priority + const configuredMime = guessMimeTypeByPath(path, filename, userRegisteredAssociations); + if (configuredMime) { + return [configuredMime, MIME_TEXT]; + } } // 2.) Registered mappings have middle priority diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewProtocols.ts b/src/vs/workbench/parts/webview/electron-browser/webviewProtocols.ts index 5b2fadb82f9..22f38917553 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewProtocols.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewProtocols.ts @@ -52,5 +52,5 @@ const webviewMimeTypes = { function getMimeType(normalizedPath: URI) { const ext = extname(normalizedPath.fsPath).toLowerCase(); - return webviewMimeTypes[ext] || getMediaMime(normalizedPath.fsPath) || guessMimeTypes(normalizedPath.fsPath)[0]; + return webviewMimeTypes[ext] || getMediaMime(normalizedPath.fsPath) || guessMimeTypes(normalizedPath.fsPath, undefined, true)[0]; } -- GitLab