This commit is contained in:
Brent Simmons committed 2026-10-22 10:34:05 -07:00
commit 8a25604a65
3 files changed
+55 -2

No files matched your search

@@ -113,8 +113,9 @@ import Account
// Some feeds embed a full HTML document as the article content —
// render just the body fragment.
// <https://github.com/Ranchero-Software/NetNewsWire/issues/3008>
var articleBody: String
if let content = extractedArticle?.content {
self.body = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(content)
articleBody = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(content)
self.baseURL = extractedArticle?.url
} else {
let feedURL = article?.feed?.url
@@ -122,9 +123,14 @@ import Account
var articleBody = ArticleRenderingSpecialCases.extractBodyFragmentIfNeeded(article?.body ?? "")
articleBody = ArticleRenderingSpecialCases.insertParagraphTagsIfNeeded(articleBody, feedURL: feedURL, homePageURL: homePageURL)
articleBody = ArticleRenderingSpecialCases.removeStrayLineBreaksIfNeeded(articleBody, feedURL: feedURL, homePageURL: homePageURL)
self.body = articleBody
if article?.account?.type == .freshRSS {
articleBody = ArticleRenderingSpecialCases.desanitizeFreshRSSContent(articleBody)
}
self.body = articleBody
self.baseURL = article?.baseURL?.absoluteString
}
self.body = articleBody
}
// MARK: - API
@@ -231,4 +231,19 @@ 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 {
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
})
}
}
@@ -139,4 +139,36 @@ 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, about `data-sanitized-class`.
<a href="#footnote-1-ref" data-sanitized-class="footnoteBackLink">Go back to content</a>
</p>
</li>
<li data-sanitized-id="footnote-2"><p>Another footnote, about `data-sanitized-id`.<a href="#footnote-2-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, about `data-sanitized-class`.
<a href="#footnote-1-ref" class="footnoteBackLink">Go back to content</a>
</p>
</li>
<li id="footnote-2"><p>Another footnote, about `data-sanitized-id`.<a href="#footnote-2-ref" class="footnoteBackLink">Go back to content</a></p></li>
</div>
"""
#expect(ArticleRenderingSpecialCases.desanitizeFreshRSSContent(sanitized) == expected)
}
}