From 6432162e66ea66c376809a05d512efc203391437 Mon Sep 17 00:00:00 2001 From: Dan Berglund Date: Tue, 6 Oct 2026 10:17:42 +0200 Subject: [PATCH] fix: De-sanitize parts of FreshRSS sanitized HTML. This de-sanitizes HTML from FreshRSS, which allows inline footnotes to work properly. Initially I tried fixing this by adding workarounds in `newsfoot.js`, but I realized that we also use some CSS for the footnotes (notably to hide the backlink in the popover). Thus it seems like a reasonable solution to just de-sanitize the `id` and `class` attributes that we need. This can be tested by subscribing/reading an article through FreshRSS. Without this fix the footnotes will be "dumb" and just link out to Safari, and with the fix they will properly be shown inline. Here's two recent-ish articles with footnotes that can be tested: - https://daringfireball.net/2026/09/iphone_4_antennagate_q_and_a - https://www.seangoedecke.com/shipping-is-the-foundation/ Fixes: #5472 --- .../Article Rendering/ArticleRenderer.swift | 6 ++-- .../ArticleRenderingSpecialCases.swift | 9 ++++++ .../ArticleRenderingSpecialCasesTests.swift | 31 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index ba859a4ed..7a94f0723 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -114,11 +114,13 @@ import Account // render just the body fragment. // if let content = extractedArticle?.content { - self.body = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(content) + let body = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(content) + self.body = ArticleRenderingSpecialCases.desanitizeFreshRSSContent(body) self.baseURL = extractedArticle?.url } else { let articleBody = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(article?.body ?? "") - self.body = ArticleRenderingSpecialCases.insertParagraphTagsIfNeeded(articleBody, feedURLString: article?.feed?.url) + let withParagraphs = ArticleRenderingSpecialCases.insertParagraphTagsIfNeeded(articleBody, feedURLString: article?.feed?.url) + self.body = ArticleRenderingSpecialCases.desanitizeFreshRSSContent(withParagraphs) self.baseURL = article?.baseURL?.absoluteString } } diff --git a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift index 1cce9a0cf..7a027a4a1 100644 --- a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift +++ b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift @@ -200,4 +200,13 @@ struct ArticleRenderingSpecialCases { return filteredHTML } + + /// De-sanitize some parts of the HTML that FreshRSS sanitized. + /// + /// Doing this allows inline footnotes to work, without it they are broken, since they rely on matching `id` and `class` attributes. + static func desanitizeFreshRSSContent(_ content: String) -> String { + content + .replacingOccurrences(of: "data-sanitized-class", with: "class") + .replacingOccurrences(of: "data-sanitized-id", with: "id") + } } diff --git a/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift b/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift index 319ff93ba..7276120ff 100644 --- a/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift +++ b/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift @@ -102,4 +102,35 @@ import Testing let hackadayLink = try #require(URL(string: "https://hackaday.com/2025/12/01/necroprinting-isnt-as-bad-as-it-sounds/")) #expect(ArticleRenderingSpecialCases.baseURLForRendering(hackadayLink) == hackadayLink) } + + // MARK: De-sanizite FreshRSS content + @Test( + "The sanitization happening in FreshRSS breaks inline footnotes, so we de-sanitize id and class attributes", + .bug("https://github.com/Ranchero-Software/NetNewsWire/issues/5472") + ) + func freshRSSContent_desanitizedIdAndClass(){ + let sanitized = """ +
+
  • +

    + This is the footnote content + Go back to content +

    +
  • +
    +""" + let expected = """ +
    +
  • +

    + This is the footnote content + Go back to content +

    +
  • +
    +""" + + #expect(ArticleRenderingSpecialCases.desanitizeFreshRSSContent(sanitized) == expected) + } + }