Removing pointless URL building in url blocklist regex.

This commit is contained in:
Dessalines 2024-04-22 15:14:52 -04:00
parent 0e2b3952bf
commit 7f5fcf882e

View file

@ -536,17 +536,8 @@ pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult<RegexSet>
.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)