Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Local] Fix HTML escaped characters in titles #757

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jocmp.capy.accounts.local

import com.jocmp.rssparser.model.RssItem
import org.jsoup.Jsoup
import org.jsoup.safety.Cleaner
import org.jsoup.safety.Safelist
import java.net.URI
import java.net.URL
Expand Down Expand Up @@ -34,7 +35,11 @@ internal class ParsedItem(private val item: RssItem, private val siteURL: String
}

val title: String
get() = Jsoup.clean(item.title.orEmpty(), Safelist.none())
get() {
val cleaner = Cleaner(Safelist.none())

return cleaner.clean(Jsoup.parse(item.title.orEmpty())).text()
}

val imageURL: String?
get() = cleanedURL(item.image)?.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class ParsedItemTest {
@Test
fun title_withNestedHTML() {
val title =
"<mark>The `&lt;details&gt;` and `&lt;summary&gt;` elements are getting an upgrade</mark>"
"<mark>The `&lt;details&gt;` &amp; `&lt;summary&gt;` elements are getting an upgrade</mark>"

val item = RssItem.Builder().title(title).build()
val parsedItem = ParsedItem(item, siteURL = "")

assertEquals(
expected = "The `&lt;details&gt;` and `&lt;summary&gt;` elements are getting an upgrade",
expected = "The `<details>` & `<summary>` elements are getting an upgrade",
actual = parsedItem.title
)
}
Expand Down
Loading