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