From ed599451568058407df67de93a79f831aaadaa6e Mon Sep 17 00:00:00 2001 From: Meghan Kulkarni Date: Mon, 31 Jul 2023 11:36:21 -0700 Subject: [PATCH] Links with no authority are considered invalid (#189323) * edit validateLink --- .../src/languageFeatures/copyFiles/copyPasteLinks.ts | 2 +- .../markdown-language-features/src/test/markdownLink.test.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/markdown-language-features/src/languageFeatures/copyFiles/copyPasteLinks.ts b/extensions/markdown-language-features/src/languageFeatures/copyFiles/copyPasteLinks.ts index ab7b9b60d65..79829dc1197 100644 --- a/extensions/markdown-language-features/src/languageFeatures/copyFiles/copyPasteLinks.ts +++ b/extensions/markdown-language-features/src/languageFeatures/copyFiles/copyPasteLinks.ts @@ -57,7 +57,7 @@ export function validateLink(urlList: string): { isValid: boolean; cleanedUrlLis } const splitUrlList = trimmedUrlList.split(' ').filter(item => item !== ''); //split on spaces and remove empty strings if (uri) { - isValid = splitUrlList.length === 1 && !splitUrlList[0].includes('\n') && externalUriSchemes.includes(vscode.Uri.parse(splitUrlList[0]).scheme); + isValid = splitUrlList.length === 1 && !splitUrlList[0].includes('\n') && externalUriSchemes.includes(vscode.Uri.parse(splitUrlList[0]).scheme) && !!vscode.Uri.parse(splitUrlList[0]).authority; } return { isValid, cleanedUrlList: splitUrlList[0] }; } diff --git a/extensions/markdown-language-features/src/test/markdownLink.test.ts b/extensions/markdown-language-features/src/test/markdownLink.test.ts index 05a08b10463..ea39cba1bdb 100644 --- a/extensions/markdown-language-features/src/test/markdownLink.test.ts +++ b/extensions/markdown-language-features/src/test/markdownLink.test.ts @@ -94,6 +94,11 @@ suite('createEditAddingLinksForUriList', () => { const isLink = validateLink('https://www.microsoft.com/ \r\nhttps://www.microsoft.com/\r\nhttps://www.microsoft.com/\r\n hello \r\nhttps://www.microsoft.com/').isValid; assert.strictEqual(isLink, false); }); + + test('Markdown pasting should not occur for just a valid uri scheme', () => { + const isLink = validateLink('https://').isValid; + assert.strictEqual(isLink, false); + }); }); suite('appendToLinkSnippet', () => {