From 9b71822be6b3dc9fc044971941eb4855229aad13 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Tue, 26 Dec 2023 15:11:16 -0500 Subject: [PATCH] Match on both http and https in format_url (414) --- src/utils.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 5cf4b7d..09c2d5a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -780,20 +780,20 @@ pub async fn catch_random(sub: &str, additional: &str) -> Result, } } -static REGEX_URL_WWW: Lazy = Lazy::new(|| Regex::new(r"https://www\.reddit\.com/(.*)").unwrap()); -static REGEX_URL_OLD: Lazy = Lazy::new(|| Regex::new(r"https://old\.reddit\.com/(.*)").unwrap()); -static REGEX_URL_NP: Lazy = Lazy::new(|| Regex::new(r"https://np\.reddit\.com/(.*)").unwrap()); -static REGEX_URL_PLAIN: Lazy = Lazy::new(|| Regex::new(r"https://reddit\.com/(.*)").unwrap()); -static REGEX_URL_VIDEOS: Lazy = Lazy::new(|| Regex::new(r"https://v\.redd\.it/(.*)/DASH_([0-9]{2,4}(\.mp4|$|\?source=fallback))").unwrap()); -static REGEX_URL_VIDEOS_HLS: Lazy = Lazy::new(|| Regex::new(r"https://v\.redd\.it/(.+)/(HLSPlaylist\.m3u8.*)$").unwrap()); -static REGEX_URL_IMAGES: Lazy = Lazy::new(|| Regex::new(r"https://i\.redd\.it/(.*)").unwrap()); -static REGEX_URL_THUMBS_A: Lazy = Lazy::new(|| Regex::new(r"https://a\.thumbs\.redditmedia\.com/(.*)").unwrap()); -static REGEX_URL_THUMBS_B: Lazy = Lazy::new(|| Regex::new(r"https://b\.thumbs\.redditmedia\.com/(.*)").unwrap()); -static REGEX_URL_EMOJI: Lazy = Lazy::new(|| Regex::new(r"https://emoji\.redditmedia\.com/(.*)/(.*)").unwrap()); -static REGEX_URL_PREVIEW: Lazy = Lazy::new(|| Regex::new(r"https://preview\.redd\.it/(.*)").unwrap()); -static REGEX_URL_EXTERNAL_PREVIEW: Lazy = Lazy::new(|| Regex::new(r"https://external\-preview\.redd\.it/(.*)").unwrap()); -static REGEX_URL_STYLES: Lazy = Lazy::new(|| Regex::new(r"https://styles\.redditmedia\.com/(.*)").unwrap()); -static REGEX_URL_STATIC_MEDIA: Lazy = Lazy::new(|| Regex::new(r"https://www\.redditstatic\.com/(.*)").unwrap()); +static REGEX_URL_WWW: Lazy = Lazy::new(|| Regex::new(r"https?://www\.reddit\.com/(.*)").unwrap()); +static REGEX_URL_OLD: Lazy = Lazy::new(|| Regex::new(r"https?://old\.reddit\.com/(.*)").unwrap()); +static REGEX_URL_NP: Lazy = Lazy::new(|| Regex::new(r"https?://np\.reddit\.com/(.*)").unwrap()); +static REGEX_URL_PLAIN: Lazy = Lazy::new(|| Regex::new(r"https?://reddit\.com/(.*)").unwrap()); +static REGEX_URL_VIDEOS: Lazy = Lazy::new(|| Regex::new(r"https?://v\.redd\.it/(.*)/DASH_([0-9]{2,4}(\.mp4|$|\?source=fallback))").unwrap()); +static REGEX_URL_VIDEOS_HLS: Lazy = Lazy::new(|| Regex::new(r"https?://v\.redd\.it/(.+)/(HLSPlaylist\.m3u8.*)$").unwrap()); +static REGEX_URL_IMAGES: Lazy = Lazy::new(|| Regex::new(r"https?://i\.redd\.it/(.*)").unwrap()); +static REGEX_URL_THUMBS_A: Lazy = Lazy::new(|| Regex::new(r"https?://a\.thumbs\.redditmedia\.com/(.*)").unwrap()); +static REGEX_URL_THUMBS_B: Lazy = Lazy::new(|| Regex::new(r"https?://b\.thumbs\.redditmedia\.com/(.*)").unwrap()); +static REGEX_URL_EMOJI: Lazy = Lazy::new(|| Regex::new(r"https?://emoji\.redditmedia\.com/(.*)/(.*)").unwrap()); +static REGEX_URL_PREVIEW: Lazy = Lazy::new(|| Regex::new(r"https?://preview\.redd\.it/(.*)").unwrap()); +static REGEX_URL_EXTERNAL_PREVIEW: Lazy = Lazy::new(|| Regex::new(r"https?://external\-preview\.redd\.it/(.*)").unwrap()); +static REGEX_URL_STYLES: Lazy = Lazy::new(|| Regex::new(r"https?://styles\.redditmedia\.com/(.*)").unwrap()); +static REGEX_URL_STATIC_MEDIA: Lazy = Lazy::new(|| Regex::new(r"https?://www\.redditstatic\.com/(.*)").unwrap()); // Direct urls to proxy if proxy is enabled pub fn format_url(url: &str) -> String { @@ -853,7 +853,7 @@ pub fn format_url(url: &str) -> String { } static REDDIT_REGEX: Lazy = Lazy::new(|| Regex::new(r#"href="(https|http|)://(www\.|old\.|np\.|amp\.|)(reddit\.com|redd\.it)/"#).unwrap()); -static REDDIT_PREVIEW_REGEX: Lazy = Lazy::new(|| Regex::new(r"https://external-preview\.redd\.it(.*)[^?]").unwrap()); +static REDDIT_PREVIEW_REGEX: Lazy = Lazy::new(|| Regex::new(r"https?://external-preview\.redd\.it(.*)[^?]").unwrap()); // Rewrite Reddit links to Libreddit in body of text pub fn rewrite_urls(input_text: &str) -> String {