From a19089023902b581134a384de57431e58eb92d6c Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Sat, 17 Jul 2021 22:24:28 -0700 Subject: [PATCH] Fix Regex matching of Reddit links --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 2 +- src/utils.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 595102c..0ef9640 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -609,7 +609,7 @@ checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "libreddit" -version = "0.14.9" +version = "0.14.10" dependencies = [ "askama", "async-recursion", diff --git a/Cargo.toml b/Cargo.toml index d828002..bb9a6cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libreddit" description = " Alternative private front-end to Reddit" license = "AGPL-3.0" repository = "https://github.com/spikecodes/libreddit" -version = "0.14.9" +version = "0.14.10" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2018" diff --git a/src/main.rs b/src/main.rs index 9f85b29..3046497 100644 --- a/src/main.rs +++ b/src/main.rs @@ -251,7 +251,7 @@ async fn main() { app.at("/:id").get(|req: Request| match req.param("id").as_deref() { // Sort front page - Some("best") | Some("hot") | Some("new") | Some("top") | Some("rising") | Some("controversial") => subreddit::community(req).boxed(), + Some("best" | "hot" | "new" | "top" | "rising" | "controversial") => subreddit::community(req).boxed(), // Short link for post Some(id) if id.len() > 4 && id.len() < 7 => post::item(req).boxed(), // Error message for unknown pages diff --git a/src/utils.rs b/src/utils.rs index e4ac319..e5ddd5f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -518,7 +518,7 @@ pub fn format_url(url: &str) -> String { // Rewrite Reddit links to Libreddit in body of text pub fn rewrite_urls(input_text: &str) -> String { - let text1 = Regex::new(r#"href="(https|http|)://(www.|old.|np.|amp.|)(reddit.com|redd.it)/"#).map_or(String::new(), |re| re.replace_all(input_text, r#"href="/"#).to_string()); + let text1 = Regex::new(r#"href="(https|http|)://(www\.|old\.|np\.|amp\.|)(reddit\.com|redd\.it)/"#).map_or(String::new(), |re| re.replace_all(input_text, r#"href="/"#).to_string()); // Rewrite external media previews to Libreddit Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").map_or(String::new(), |re| {