From 7f5fcf882e495bad3c32fcdca399701d76509925 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 22 Apr 2024 15:14:52 -0400 Subject: [PATCH] Removing pointless URL building in url blocklist regex. --- crates/api_common/src/utils.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index d2118dcdf..4ab587928 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -536,17 +536,8 @@ pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult .try_get_with::<_, LemmyError>((), async { let urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?; - let regexes = urls.iter().map(|url| { - // The scheme is removed in the saving, - // so fake it here to build the url. - let url = &format!("https://{}", url.url); - let parsed = Url::parse(url).expect("Couldn't parse URL."); - format!( - "{}{}", - escape(parsed.host_str().expect("No domain.")), - escape(parsed.path()) - ) - }); + // The urls are already validated on saving, so just escape them. + let regexes = urls.iter().map(|url| escape(&url.url)); let set = RegexSet::new(regexes)?; Ok(set)