mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 10:22:35 +00:00
Improved regex, that's not greedy and only matches inside html tags
This commit is contained in:
2 files changed
+4
-3
No files matched your search
@@ -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
|
||||
|
||||
@@ -117,6 +117,7 @@ import Testing
|
||||
<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 = """
|
||||
@@ -127,10 +128,10 @@ import Testing
|
||||
<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)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user