From 6432162e66ea66c376809a05d512efc203391437 Mon Sep 17 00:00:00 2001 From: Dan Berglund Date: Tue, 6 Oct 2026 10:17:42 +0200 Subject: [PATCH 1/4] 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) + } + } From fc7416e10df4155707c2b2b96da8c082e7c8c46f Mon Sep 17 00:00:00 2001 From: Dan Berglund Date: Wed, 7 Oct 2026 08:49:50 +0200 Subject: [PATCH 2/4] Only match `data-sanitized-(id|class)` inside html tags --- .../ArticleRenderingSpecialCases.swift | 12 +++++++++--- .../ArticleRenderingSpecialCasesTests.swift | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift index 7a027a4a1..5410d673a 100644 --- a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift +++ b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift @@ -205,8 +205,14 @@ struct ArticleRenderingSpecialCases { /// /// 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") + let classRegex = /(?'open'<.*)data-sanitized-class(?'close'.*>)/ + let idRegex = /(?'open'<.*)data-sanitized-id(?'close'.*>)/ + return content + .replacing(classRegex, with: { match in + match.output.open + "class" + match.output.close + }) + .replacing(idRegex, with: { match in + match.output.open + "id" + match.output.close + }) } } diff --git a/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift b/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift index 7276120ff..08bc4b845 100644 --- a/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift +++ b/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift @@ -108,12 +108,12 @@ import Testing "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(){ + func freshRSSContent_desanitizedIDAndClass(){ let sanitized = """
  • - This is the footnote content + This is the footnote content, about `data-sanitized-class`. Go back to content

  • @@ -123,7 +123,7 @@ import Testing
  • - This is the footnote content + This is the footnote content, about `data-sanitized-class`. Go back to content

  • From 6dc14b331d310b2d4dddb04c0daabeff60b6d6b0 Mon Sep 17 00:00:00 2001 From: Dan Berglund Date: Wed, 7 Oct 2026 08:58:54 +0200 Subject: [PATCH 3/4] Only do desanitization for articles from FreshRSS feeds --- Shared/Article Rendering/ArticleRenderer.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index 7a94f0723..b2d4dad79 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -113,16 +113,19 @@ import Account // Some feeds embed a full HTML document as the article content — // render just the body fragment. // + var articleBody: String if let content = extractedArticle?.content { - let body = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(content) - self.body = ArticleRenderingSpecialCases.desanitizeFreshRSSContent(body) + articleBody = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(content) self.baseURL = extractedArticle?.url } else { - let articleBody = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(article?.body ?? "") - let withParagraphs = ArticleRenderingSpecialCases.insertParagraphTagsIfNeeded(articleBody, feedURLString: article?.feed?.url) - self.body = ArticleRenderingSpecialCases.desanitizeFreshRSSContent(withParagraphs) + articleBody = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(article?.body ?? "") + articleBody = ArticleRenderingSpecialCases.insertParagraphTagsIfNeeded(articleBody, feedURLString: article?.feed?.url) self.baseURL = article?.baseURL?.absoluteString } + if article?.account?.type == .freshRSS { + articleBody = ArticleRenderingSpecialCases.desanitizeFreshRSSContent(articleBody) + } + self.body = articleBody } // MARK: - API From bdf638ba304371dbfcb9ba127ef85732c3f7ff92 Mon Sep 17 00:00:00 2001 From: Dan Berglund Date: Thu, 8 Oct 2026 19:14:07 +0200 Subject: [PATCH 4/4] Improved regex, that's not greedy and only matches inside html tags --- Shared/Article Rendering/ArticleRenderingSpecialCases.swift | 4 ++-- .../NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift index 5410d673a..7f4fdecda 100644 --- a/Shared/Article Rendering/ArticleRenderingSpecialCases.swift +++ b/Shared/Article Rendering/ArticleRenderingSpecialCases.swift @@ -205,8 +205,8 @@ struct ArticleRenderingSpecialCases { /// /// 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 { - let classRegex = /(?'open'<.*)data-sanitized-class(?'close'.*>)/ - let idRegex = /(?'open'<.*)data-sanitized-id(?'close'.*>)/ + let classRegex = /(?'open'<[^>]*?)data-sanitized-class(?'close'[^<]*?>)/ + let idRegex = /(?'open'<[^>]*?)data-sanitized-id(?'close'[^<]*?>)/ return content .replacing(classRegex, with: { match in match.output.open + "class" + match.output.close diff --git a/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift b/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift index 08bc4b845..ffa78bc00 100644 --- a/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift +++ b/Tests/NetNewsWireTests/ArticleRenderingSpecialCasesTests.swift @@ -117,6 +117,7 @@ import Testing Go back to content

    +
  • Another footnote, about `data-sanitized-id`.Go back to content

  • """ let expected = """ @@ -127,10 +128,10 @@ import Testing Go back to content

    +
  • Another footnote, about `data-sanitized-id`.Go back to content

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