From 8266e1c67b0dff28fc8fa24ecde325e8a7e91cd6 Mon Sep 17 00:00:00 2001 From: Pine Wu Date: Thu, 3 Oct 2019 11:44:56 -0700 Subject: [PATCH] Fix #81843 --- .../trustedDomainsFileSystemProvider.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/url/common/trustedDomainsFileSystemProvider.ts b/src/vs/workbench/contrib/url/common/trustedDomainsFileSystemProvider.ts index ba66812aab7..d007281fc3b 100644 --- a/src/vs/workbench/contrib/url/common/trustedDomainsFileSystemProvider.ts +++ b/src/vs/workbench/contrib/url/common/trustedDomainsFileSystemProvider.ts @@ -33,8 +33,7 @@ const TRUSTED_DOMAINS_STAT: IStat = { size: 0 }; -const CONFIG_HELP_TEXT_PRE = - `// Links matching one or more entries in the list below can be opened without link protection. +const CONFIG_HELP_TEXT_PRE = `// Links matching one or more entries in the list below can be opened without link protection. // The following examples show what entries can look like: // - "https://microsoft.com": Matches this specific domain using https // - "https://*.microsoft.com": Match all domains ending in "microsoft.com" using https @@ -95,23 +94,36 @@ export class TrustedDomainsFileSystemProvider implements IFileSystemProvider, IW } readFile(resource: URI): Promise { - const { defaultTrustedDomains, trustedDomains } = readTrustedDomains(this.storageService, this.productService); + let trustedDomainsContent = this.storageService.get( + 'http.linkProtectionTrustedDomainsContent', + StorageScope.GLOBAL + ); + + if ( + !trustedDomainsContent || + trustedDomainsContent.indexOf(CONFIG_HELP_TEXT_PRE) === -1 || + trustedDomainsContent.indexOf(CONFIG_HELP_TEXT_AFTER) === -1 + ) { + const { defaultTrustedDomains, trustedDomains } = readTrustedDomains(this.storageService, this.productService); + + trustedDomainsContent = computeTrustedDomainContent(defaultTrustedDomains, trustedDomains); + } - const trustedDomainsContent = computeTrustedDomainContent(defaultTrustedDomains, trustedDomains); const buffer = VSBuffer.fromString(trustedDomainsContent).buffer; return Promise.resolve(buffer); } writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise { try { - const trustedDomains = parse(content.toString()); + const trustedDomainsContent = content.toString(); + const trustedDomains = parse(trustedDomainsContent); + this.storageService.store('http.linkProtectionTrustedDomainsContent', trustedDomainsContent, StorageScope.GLOBAL); this.storageService.store( 'http.linkProtectionTrustedDomains', JSON.stringify(trustedDomains), StorageScope.GLOBAL ); - } catch (err) { } return Promise.resolve();