Avoid uri parse warnings for markdown uris

Fixes #58566

We only support local file links or a small set of normal schemes, like `http` and `mailto`. Use this to avoid calling `Uri.parse` with scheme-less paths such as `Uri.parse('/images/cat.gif')`
This commit is contained in:
Matt Bierner
2018-09-13 14:28:59 -07:00
parent de57f74a3a
commit 4096b5d68e
3 changed files with 46 additions and 14 deletions

View File

@@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
const knownSchemes = ['http:', 'https:', 'file:', 'mailto:'];
export function getUriForLinkWithKnownExternalScheme(
link: string,
): vscode.Uri | undefined {
if (knownSchemes.some(knownScheme => link.toLowerCase().startsWith(knownScheme))) {
return vscode.Uri.parse(link);
}
return undefined;
}