···11import escapeHTML from 'escape-html'
2233export function linkRedirectContents(link: string): string {
44+ // Encode characters that could break out of the single-quoted URL in meta refresh.
55+ // HTML entity escaping (') is insufficient because the browser decodes entities
66+ // before the meta refresh parser processes the URL, allowing apostrophes to
77+ // prematurely terminate the URL string.
88+ //
99+ // Example: "They're" with HTML escaping becomes "They're" in HTML, but after
1010+ // the browser decodes the content attribute, the meta refresh parser sees "They're"
1111+ // and interprets the apostrophe as the closing quote, truncating the URL to "They".
1212+ const safeLink = link.replace(/'/g, '%27')
1313+414 return `
515 <html>
616 <head>
77- <meta http-equiv="refresh" content="0; URL='${escapeHTML(link)}'" />
1717+ <meta http-equiv="refresh" content="0; URL='${escapeHTML(safeLink)}'" />
818 <meta
919 http-equiv="Cache-Control"
1020 content="no-store, no-cache, must-revalidate, max-age=0" />