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
This commit is contained in:
Dan Berglund committed 2026-10-06 10:17:42 +02:00
1 parent 8c322c287b
commit 6432162e66
3 files changed
+44 -2

No files matched your search

@@ -114,11 +114,13 @@ import Account
// render just the body fragment.
// <https://github.com/Ranchero-Software/NetNewsWire/issues/3008>
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
}
}
@@ -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")
}
}
@@ -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 = """
<div data-sanitized-class="footnotes">
<li data-sanitized-id="footnote-1">
<p>
This is the footnote content
<a href="#footnote-1-ref" data-sanitized-class="footnoteBackLink">Go back to content</a>
</p>
</li>
</div>
"""
let expected = """
<div class="footnotes">
<li id="footnote-1">
<p>
This is the footnote content
<a href="#footnote-1-ref" class="footnoteBackLink">Go back to content</a>
</p>
</li>
</div>
"""
#expect(ArticleRenderingSpecialCases.desanitizeFreshRSSContent(sanitized) == expected)
}
}