Skip to content

Commit ed59945

Browse files
Links with no authority are considered invalid (microsoft#189323)
* edit validateLink
1 parent f7d59ef commit ed59945

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

extensions/markdown-language-features/src/languageFeatures/copyFiles/copyPasteLinks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function validateLink(urlList: string): { isValid: boolean; cleanedUrlLis
5757
}
5858
const splitUrlList = trimmedUrlList.split(' ').filter(item => item !== ''); //split on spaces and remove empty strings
5959
if (uri) {
60-
isValid = splitUrlList.length === 1 && !splitUrlList[0].includes('\n') && externalUriSchemes.includes(vscode.Uri.parse(splitUrlList[0]).scheme);
60+
isValid = splitUrlList.length === 1 && !splitUrlList[0].includes('\n') && externalUriSchemes.includes(vscode.Uri.parse(splitUrlList[0]).scheme) && !!vscode.Uri.parse(splitUrlList[0]).authority;
6161
}
6262
return { isValid, cleanedUrlList: splitUrlList[0] };
6363
}

extensions/markdown-language-features/src/test/markdownLink.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ suite('createEditAddingLinksForUriList', () => {
9494
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;
9595
assert.strictEqual(isLink, false);
9696
});
97+
98+
test('Markdown pasting should not occur for just a valid uri scheme', () => {
99+
const isLink = validateLink('https://').isValid;
100+
assert.strictEqual(isLink, false);
101+
});
97102
});
98103

99104
suite('appendToLinkSnippet', () => {

0 commit comments

Comments
 (0)