Remove negative lookbehind in regexp

Fixes #145655
This commit is contained in:
Matt Bierner
2022-03-22 14:34:15 -07:00
parent 23f9da2209
commit d2db6fb2d0
2 changed files with 9 additions and 10 deletions

View File

@@ -104,8 +104,7 @@ export function stripAngleBrackets(link: string) {
}
const linkPattern = /(\[((!\[[^\]]*?\]\(\s*)([^\s\(\)]+?)\s*\)\]|(?:\\\]|[^\]])*\])\(\s*)(([^\s\(\)]|\([^\s\(\)]*?\))+)\s*(".*?")?\)/g;
// eslint-disable-next-line code-no-look-behind-regex
const referenceLinkPattern = /((?<=^|[^\]])\[((?:\\\]|[^\]])+)\])(?!:)(?:[^\[]|$|\[\s*?([^\s\]]*?)\])/g;
const referenceLinkPattern = /(?:(\[((?:\\\]|[^\]])+)\]\[\s*?)([^\s\]]*?)\]|\[\s*?([^\s\]]*?)\])(?!\:)/g;
const definitionPattern = /^([\t ]*\[(?!\^)((?:\\\]|[^\]])+)\]:\s*)([^<]\S*|<[^>]+>)/gm;
const inlineCodePattern = /(?:^|[^`])(`+)(?:.+?|.*?(?:(?:\r?\n).+?)*?)(?:\r?\n)?\1(?:$|[^`])/gm;
@@ -187,14 +186,14 @@ export default class LinkProvider implements vscode.DocumentLinkProvider {
let reference = match[3];
if (reference) { // [text][ref]
const pre = match[1];
const offset = (match.index || 0) + pre.length + 1;
const offset = (match.index || 0) + pre.length;
linkStart = document.positionAt(offset);
linkEnd = document.positionAt(offset + reference.length);
} else if (match[2]) { // [ref][], [ref]
reference = match[2];
} else if (match[4]) { // [ref][], [ref]
reference = match[4];
const offset = (match.index || 0) + 1;
linkStart = document.positionAt(offset);
linkEnd = document.positionAt(offset + match[2].length);
linkEnd = document.positionAt(offset + reference.length);
} else {
continue;
}

View File

@@ -159,16 +159,16 @@ suite('markdown.DocumentLinkProvider', () => {
assert.strictEqual(links.length, 1);
});
test('Should find links for referenes with only one [] (#141285)', async () => {
test('Should find links for referees with only one [] (#141285)', async () => {
let links = await getLinksForFile([
'[Works]',
'[Works]: https://microsoft.com',
'[ref]',
'[ref]: https://microsoft.com',
].join('\n'));
assert.strictEqual(links.length, 2);
links = await getLinksForFile([
'[Does Not Work]',
'[Works]: https://microsoft.com',
'[def]: https://microsoft.com',
].join('\n'));
assert.strictEqual(links.length, 1);
});