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

fix: added support for inline base64 encoded data images #584

Merged
merged 1 commit into from
Feb 5, 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 @@ -148,20 +148,13 @@ data class FeedItem
?: plainText
).take(MAX_SNIPPET_LENGTH)

// Make double sure no base64 images are used as thumbnails
val safeImage =
when {
entry.image?.url?.startsWith("data") == true -> null
else -> entry.image
}

this.guid = entryGuid
entry.title?.let { this.plainTitle = it.take(MAX_TITLE_LENGTH) }
@Suppress("DEPRECATION")
this.title = this.plainTitle
this.plainSnippet = summary

this.thumbnailImage = safeImage
this.thumbnailImage = entry.image
val firstEnclosure = entry.attachments?.firstOrNull()
this.enclosureLink = firstEnclosure?.url
this.enclosureType = firstEnclosure?.mime_type?.lowercase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,6 @@ class RssLocalSync(
}
}
}
}.map {
// Double check that icon is not base64
when {
it.icon?.startsWith("data") == true -> it.copy(icon = null)
else -> it
}
}.onLeft {
// Nothing was parsed, nothing to do. lastSync time has already been updated
}.flatMap { feed ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,13 @@ class HtmlLinearizer {
}

absSrc.takeIf { it.isNotBlank() }?.let {
val url = resolve(baseUrl, it)
// inline data images can't be resolved, the result is an empty string
val url =
if (it.startsWith("data:")) {
it
} else {
resolve(baseUrl, it)
}
if (width != null && height != null) {
result.add(
LinearImageSource(
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/com/nononsenseapps/feeder/util/HtmlUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@ fun findFirstImageInHtml(
.filterNot { it.attr("width") == "1" || it.attr("height") == "1" }
.map {
// abs: will resolve relative urls against the baseurl
val url =
if (it.attr("abs:src").contains("data:image", ignoreCase = true)) {
return@map null
} else {
it.attr("abs:src")
}
ImageFromHTML(
url = url,
url = it.attr("abs:src"),
width = it.attr("width").toIntOrNull(),
height = it.attr("height").toIntOrNull(),
)
}.firstOrNull {
it?.url?.isNotBlank() == true &&
it.url.isNotBlank() == true &&
!it.url.contains("twitter_icon", ignoreCase = true) &&
!it.url.contains("facebook_icon", ignoreCase = true)
}
Expand Down
Loading
Loading