mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 10:22:35 +00:00
Only match data-sanitized-(id|class) inside html tags
This commit is contained in:
2 files changed
+12
-6
No files matched your search
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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 = """
|
||||
<div data-sanitized-class="footnotes">
|
||||
<li data-sanitized-id="footnote-1">
|
||||
<p>
|
||||
This is the footnote content
|
||||
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>
|
||||
@@ -123,7 +123,7 @@ import Testing
|
||||
<div class="footnotes">
|
||||
<li id="footnote-1">
|
||||
<p>
|
||||
This is the footnote content
|
||||
This is the footnote content, about `data-sanitized-class`.
|
||||
<a href="#footnote-1-ref" class="footnoteBackLink">Go back to content</a>
|
||||
</p>
|
||||
</li>
|
||||
|
||||
Reference in new issue
Block a user