From f1f22c461ea4adb0b1c9ce5af99d2b20a9df3713 Mon Sep 17 00:00:00 2001 From: Alex Hedges Date: Sun, 19 Feb 2023 00:56:26 -0500 Subject: [PATCH] Escape feed titles and URLs in OPML export The export feature was failing to produce valid XML because it did not escape any characters when generating XML. Although most of the characters are uncommon in this situation, ampersands are common in URLs, which caused me to notice this problem. --- src/manage/export.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/manage/export.ts b/src/manage/export.ts index 2e03f18..5ff0ab8 100644 --- a/src/manage/export.ts +++ b/src/manage/export.ts @@ -1,5 +1,14 @@ const link = document.getElementById("download") as HTMLAnchorElement; +function escapeXml(input: string): string { + return input + .replace("&", "&") + .replace("\"", """) + .replace("'", "'") + .replace("<", "<") + .replace(">", ">"); +} + async function exportFeeds(): Promise { const feeds: Feed[] = (await browser.storage.sync.get({ feeds: [] })).feeds; @@ -7,7 +16,7 @@ async function exportFeeds(): Promise { ${feeds - .map(f => ``) + .map(f => ``) .join("\n ")} `;