Repository: redlib-org/redlib (language: rust)

Issue:
🐛 Bug Report: rss feeds seems to be double-escaped
## Describe the bug

This issue manifests on some instances running recent code (see below)

## Steps to reproduce the bug

Steps to reproduce the behavior:
1. Import https://redlib.zaggy.nl/r/emulation.rss or https://redlib.perennialte.ch/r/emulation.rss in a rss reader
2. See the escaped html in the content


## What's the expected behavior?

Ability to see the html in the rss feed rendered properly.



## Additional context / screenshot

This is how a rendered item looks from either of the above rss feeds:

![Image](https://github.com/user-attachments/assets/d91a25a6-e6e1-4772-a6dd-573dfdc4e62a)


**CAUTION: I did not try to reproduce the issue with git master, only noticed it on a running instance.**

https://redlib.zaggy.nl/info is running https://github.com/redlib-org/redlib/commit/96ebfd2d3a6d2b7c45c6cdf7dfc65140d2288747 (nov 19, 2024, deployed 2025-01-18)

https://redlib.perennialte.ch/info is not showing what commit it is based on (deployed 2024-12-29)


- [ ] I checked that the instance that this was reported on is running the latest git commit, or I can reproduce it locally on the latest git commit



Discussion / hints:
Seeing the same thing on my personal instance running d7ec07cd0d713fc308e1004663b0053db8f00a0f deployed today

Looking into this now.

The source issue is that selftext_html https://www.reddit.com/r/emulation/hot.json is passed through to rss unmodified.

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index 819d4bc6..20d528b1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -770,6 +770,12 @@ version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
 
+[[package]]
+name = "htmlescape"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e9025058dae765dee5070ec375f591e2ba14638c63feff74f13805a72e523163"
+
 [[package]]
 name = "http"
 version = "0.2.12"
@@ -1367,6 +1373,7 @@ dependencies = [
  "dotenvy",
  "fastrand",
  "futures-lite",
+ "htmlescape",
  "hyper",
  "hyper-rustls",
  "libflate",
diff --git a/Cargo.toml b/Cargo.toml
index a1d3ec01..a4d01703 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -51,6 +51,7 @@ common-words-all = { version = "0.0.2", default-features = false, features = ["e
 hyper-rustls = { version = "0.24.2", features = [ "http2" ] }
 tegen = "0.1.4"
 serde_urlencoded = "0.7.1"
+htmlescape = "0.3.1"
 
 
 [dev-dependencies]
diff --git a/src/utils.rs b/src/utils.rs
index c15dceab..a5361075 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -7,6 +7,7 @@ use crate::config::{self, get_setting};
 //
 use crate::{client::json, server::RequestExt};
 use cookie::Cookie;
+use htmlescape::decode_html;
 use hyper::{Body, Request, Response};
 use log::error;
 use once_cell::sync::Lazy;
@@ -376,7 +377,7 @@ impl Post {
 			let awards = Awards::parse(&data["all_awardings"]);
 
 			// selftext_html is set for text posts when browsing.
-			let mut body = rewrite_urls(&val(post, "selftext_html"));
+			let mut body = rewrite_urls(&decode_html(&val(post, "selftext_html")).unwrap());
 			if body.is_empty() {
 				body = rewrite_urls(&val(post, "body_html"));
 			}


Test patch: