From 951fe400ae84bcf29342fd8702fac6355800652a Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Tue, 25 Jun 2024 19:50:00 -0400 Subject: [PATCH] fix(subreddit): handle plus-encoding errors --- src/subreddit.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/subreddit.rs b/src/subreddit.rs index 4df81b4..00edcae 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -64,7 +64,7 @@ pub async fn community(req: Request) -> Result, String> { let post_sort = req.cookie("post_sort").map_or_else(|| "hot".to_string(), |c| c.value().to_string()); let sort = req.param("sort").unwrap_or_else(|| req.param("id").unwrap_or(post_sort)); - let sub_name = req.param("sub").unwrap_or(if front_page == "default" || front_page.is_empty() { + let mut sub_name = req.param("sub").unwrap_or(if front_page == "default" || front_page.is_empty() { if subscribed.is_empty() { "popular".to_string() } else { @@ -84,6 +84,11 @@ pub async fn community(req: Request) -> Result, String> { return Ok(redirect(&["/user/", &sub_name[2..]].concat())); } + // If multi-sub, replace + with url encoded + + if sub_name.contains('+') { + sub_name = sub_name.replace('+', "%2B"); + } + // Request subreddit metadata let sub = if !sub_name.contains('+') && sub_name != subscribed && sub_name != "popular" && sub_name != "all" { // Regular subreddit