Skip to content

Commit 9736e54

Browse files
committed
Fixes issue with " in autolink link title text
1 parent f7dc254 commit 9736e54

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/annotations/autolinks.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ export class Autolinks implements Disposable {
325325
title += `\n${GlyphChars.Dash.repeat(2)}\nDetails timed out`;
326326
} else {
327327
const issueTitle = escapeMarkdown(issue.title.trim());
328+
const issueTitleQuoteEscaped = issueTitle.replace(/"/g, '\\"');
328329

329330
if (footnotes != null) {
330331
footnoteIndex = footnotes.size + 1;
@@ -340,7 +341,7 @@ export class Autolinks implements Disposable {
340341
);
341342
}
342343

343-
title += `\n${GlyphChars.Dash.repeat(2)}\n${issueTitle}\n${
344+
title += `\n${GlyphChars.Dash.repeat(2)}\n${issueTitleQuoteEscaped}\n${
344345
issue.closed ? 'Closed' : 'Opened'
345346
}, ${fromNow(issue.closedDate ?? issue.date)}`;
346347
}
@@ -371,6 +372,7 @@ export class Autolinks implements Disposable {
371372
title += `\n${GlyphChars.Dash.repeat(2)}\nDetails timed out`;
372373
} else {
373374
const issueTitle = encodeHtmlWeak(issue.title.trim());
375+
const issueTitleQuoteEscaped = issueTitle.replace(/"/g, '"');
374376

375377
if (footnotes != null) {
376378
footnoteIndex = footnotes.size + 1;
@@ -386,7 +388,7 @@ export class Autolinks implements Disposable {
386388
);
387389
}
388390

389-
title += `\n${GlyphChars.Dash.repeat(2)}\n${issueTitle}\n${
391+
title += `\n${GlyphChars.Dash.repeat(2)}\n${issueTitleQuoteEscaped}\n${
390392
issue.closed ? 'Closed' : 'Opened'
391393
}, ${fromNow(issue.closedDate ?? issue.date)}`;
392394
}
@@ -477,3 +479,13 @@ function ensureCachedRegex(ref: CacheableAutolinkReference, outputFormat: 'html'
477479

478480
return true;
479481
}
482+
483+
function escapeQuotesInLinkTitleMarkdown(s: string) {
484+
// Skip the first and last quotes
485+
return s.replace(/(?!^)".*?(?!$)"/g, match => match.replace(/"/g, '\\"'));
486+
}
487+
488+
function escapeQuotesInLinkTitleHtml(s: string) {
489+
// Skip the first and last quotes
490+
return s.replace(/(?!^)".*?(?!$)"/g, match => match.replace(/"/g, '"'));
491+
}

0 commit comments

Comments
 (0)