Browse Source

Fixes issue with " in autolink link title text

main
Eric Amodio 1 year ago
parent
commit
9736e547bb
1 changed files with 14 additions and 2 deletions
  1. +14
    -2
      src/annotations/autolinks.ts

+ 14
- 2
src/annotations/autolinks.ts View File

@ -325,6 +325,7 @@ export class Autolinks implements Disposable {
title += `\n${GlyphChars.Dash.repeat(2)}\nDetails timed out`;
} else {
const issueTitle = escapeMarkdown(issue.title.trim());
const issueTitleQuoteEscaped = issueTitle.replace(/"/g, '\\"');
if (footnotes != null) {
footnoteIndex = footnotes.size + 1;
@ -340,7 +341,7 @@ export class Autolinks implements Disposable {
);
}
title += `\n${GlyphChars.Dash.repeat(2)}\n${issueTitle}\n${
title += `\n${GlyphChars.Dash.repeat(2)}\n${issueTitleQuoteEscaped}\n${
issue.closed ? 'Closed' : 'Opened'
}, ${fromNow(issue.closedDate ?? issue.date)}`;
}
@ -371,6 +372,7 @@ export class Autolinks implements Disposable {
title += `\n${GlyphChars.Dash.repeat(2)}\nDetails timed out`;
} else {
const issueTitle = encodeHtmlWeak(issue.title.trim());
const issueTitleQuoteEscaped = issueTitle.replace(/"/g, '"');
if (footnotes != null) {
footnoteIndex = footnotes.size + 1;
@ -386,7 +388,7 @@ export class Autolinks implements Disposable {
);
}
title += `\n${GlyphChars.Dash.repeat(2)}\n${issueTitle}\n${
title += `\n${GlyphChars.Dash.repeat(2)}\n${issueTitleQuoteEscaped}\n${
issue.closed ? 'Closed' : 'Opened'
}, ${fromNow(issue.closedDate ?? issue.date)}`;
}
@ -477,3 +479,13 @@ function ensureCachedRegex(ref: CacheableAutolinkReference, outputFormat: 'html'
return true;
}
function escapeQuotesInLinkTitleMarkdown(s: string) {
// Skip the first and last quotes
return s.replace(/(?!^)".*?(?!$)"/g, match => match.replace(/"/g, '\\"'));
}
function escapeQuotesInLinkTitleHtml(s: string) {
// Skip the first and last quotes
return s.replace(/(?!^)".*?(?!$)"/g, match => match.replace(/"/g, '"'));
}

Loading…
Cancel
Save