Fix Regex matching of Reddit links

This commit is contained in:
spikecodes 2021-07-17 22:24:28 -07:00
parent ee51ce1a76
commit a190890239
No known key found for this signature in database
GPG Key ID: 004CECFF9B463BCB
4 changed files with 4 additions and 4 deletions

2
Cargo.lock generated
View File

@ -609,7 +609,7 @@ checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
[[package]] [[package]]
name = "libreddit" name = "libreddit"
version = "0.14.9" version = "0.14.10"
dependencies = [ dependencies = [
"askama", "askama",
"async-recursion", "async-recursion",

View File

@ -3,7 +3,7 @@ name = "libreddit"
description = " Alternative private front-end to Reddit" description = " Alternative private front-end to Reddit"
license = "AGPL-3.0" license = "AGPL-3.0"
repository = "https://github.com/spikecodes/libreddit" repository = "https://github.com/spikecodes/libreddit"
version = "0.14.9" version = "0.14.10"
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
edition = "2018" edition = "2018"

View File

@ -251,7 +251,7 @@ async fn main() {
app.at("/:id").get(|req: Request<Body>| match req.param("id").as_deref() { app.at("/:id").get(|req: Request<Body>| match req.param("id").as_deref() {
// Sort front page // 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 // Short link for post
Some(id) if id.len() > 4 && id.len() < 7 => post::item(req).boxed(), Some(id) if id.len() > 4 && id.len() < 7 => post::item(req).boxed(),
// Error message for unknown pages // Error message for unknown pages

View File

@ -518,7 +518,7 @@ pub fn format_url(url: &str) -> String {
// Rewrite Reddit links to Libreddit in body of text // Rewrite Reddit links to Libreddit in body of text
pub fn rewrite_urls(input_text: &str) -> String { 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 // Rewrite external media previews to Libreddit
Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").map_or(String::new(), |re| { Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").map_or(String::new(), |re| {