mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-30 08:11:20 +00:00
Fixing domain checking.
This commit is contained in:
parent
e22909697b
commit
0e2b3952bf
2 changed files with 11 additions and 19 deletions
|
@ -537,23 +537,15 @@ pub async fn get_url_blocklist(context: &LemmyContext) -> LemmyResult<RegexSet>
|
||||||
let urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
|
let urls = LocalSiteUrlBlocklist::get_all(&mut context.pool()).await?;
|
||||||
|
|
||||||
let regexes = urls.iter().map(|url| {
|
let regexes = urls.iter().map(|url| {
|
||||||
let url = &url.url;
|
// The scheme is removed in the saving,
|
||||||
let parsed = Url::parse(url).expect("Coundln't parse URL.");
|
// so fake it here to build the url.
|
||||||
if url.ends_with('/') {
|
let url = &format!("https://{}", url.url);
|
||||||
|
let parsed = Url::parse(url).expect("Couldn't parse URL.");
|
||||||
format!(
|
format!(
|
||||||
"({}://)?{}{}?",
|
"{}{}",
|
||||||
parsed.scheme(),
|
escape(parsed.host_str().expect("No domain.")),
|
||||||
escape(parsed.domain().expect("No domain.")),
|
|
||||||
escape(parsed.path())
|
escape(parsed.path())
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
format!(
|
|
||||||
"({}://)?{}{}",
|
|
||||||
parsed.scheme(),
|
|
||||||
escape(parsed.domain().expect("No domain.")),
|
|
||||||
escape(parsed.path())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let set = RegexSet::new(regexes)?;
|
let set = RegexSet::new(regexes)?;
|
||||||
|
|
|
@ -624,12 +624,12 @@ mod tests {
|
||||||
"example.com".to_string(),
|
"example.com".to_string(),
|
||||||
"http://example.com".to_string(),
|
"http://example.com".to_string(),
|
||||||
"https://example.com".to_string(),
|
"https://example.com".to_string(),
|
||||||
"https://example.blog/test?q=test2&q2=test3#test4".to_string(),
|
"https://example.com/test?q=test2&q2=test3#test4".to_string(),
|
||||||
])
|
])
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
&vec![
|
&vec![
|
||||||
"example.com/".to_string(),
|
"example.com/".to_string(),
|
||||||
"example.blog/test?q=test2&q2=test3#test4".to_string()
|
"example.com/test?q=test2&q2=test3#test4".to_string()
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue