Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad multiline matches for link definitions #193

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/languageFeatures/documentLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ function createHref(
): ExternalHref | InternalHref | undefined {
if (/^[a-z\-][a-z\-]+:/i.test(link)) {
// Looks like a uri
return { kind: HrefKind.External, uri: URI.parse(tryDecodeUri(link)) };
try {
return { kind: HrefKind.External, uri: URI.parse(tryDecodeUri(link)) };
} catch (e) {
console.warn(r`Failed to parse link ${link} in ${sourceDocUri.toString(true)}`);
return undefined;
}
}

const resolved = resolveInternalDocumentLink(sourceDocUri, link, workspace);
Expand Down Expand Up @@ -185,7 +190,7 @@ const autoLinkPattern = /(?<!\\)\<(\w+:[^\>\s]+)\>/g;
/**
* Matches `[text]: link`
*/
const definitionPattern = /^([\t ]*(?<!\\)\[(?!\^)((?:\\\]|[^\]])+)\]:\s*)([^<]\S*|<(?:\\[<>]|[^<>])+>)/gm;
const definitionPattern = /^([\t ]*(?<!\\)\[(?!\^)((?:\\\]|[^\]])+)\]:[\t ]*)([^<]\S*|<(?:\\[<>]|[^<>])+>)/gm;

class InlineRanges {

Expand Down
10 changes: 10 additions & 0 deletions src/test/documentLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,16 @@ suite('Link computer', () => {

assertLinksEqual(links, []);
});

test('Should not crash on definition that spans multiple lines (#192)', async () => {
const links = await getLinksForText(joinLines(
`Options`,
`[positional parameters]:`,
`-R: recursively list subdirectories.`,
));

assertLinksEqual(links, []);
});
});


Expand Down
Loading