From: Nutomic Date: Wed, 27 Jul 2022 21:03:44 +0000 (+0000) Subject: Fix panics in search_by_apub_id() (fixes #2371) (#2373) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%7Bthis.state.thumbnail%7D?a=commitdiff_plain;h=b9f1fc05185acadb3e04241e922d0ecf0b1ea8c5;p=lemmy.git Fix panics in search_by_apub_id() (fixes #2371) (#2373) --- diff --git a/crates/apub/src/fetcher/search.rs b/crates/apub/src/fetcher/search.rs index 1622e451..00fbf67f 100644 --- a/crates/apub/src/fetcher/search.rs +++ b/crates/apub/src/fetcher/search.rs @@ -32,9 +32,11 @@ pub async fn search_by_apub_id( .await } Err(_) => { - let (kind, identifier) = query.split_at(1); + let mut chars = query.chars(); + let kind = chars.next(); + let identifier = chars.as_str(); match kind { - "@" => { + Some('@') => { let id = webfinger_resolve_actor::(identifier, context, request_counter).await?; Ok(SearchableObjects::Person( @@ -43,7 +45,7 @@ pub async fn search_by_apub_id( .await?, )) } - "!" => { + Some('!') => { let id = webfinger_resolve_actor::(identifier, context, request_counter).await?; Ok(SearchableObjects::Community( diff --git a/crates/apub/src/fetcher/webfinger.rs b/crates/apub/src/fetcher/webfinger.rs index 8dda8ae1..80dd3bc6 100644 --- a/crates/apub/src/fetcher/webfinger.rs +++ b/crates/apub/src/fetcher/webfinger.rs @@ -39,7 +39,7 @@ where let (_, domain) = identifier .splitn(2, '@') .collect_tuple() - .expect("invalid query"); + .ok_or_else(|| LemmyError::from_message("Invalid webfinger query, missing domain"))?; let fetch_url = format!( "{}://{}/.well-known/webfinger?resource=acct:{}", protocol, domain, identifier