From b9f1fc05185acadb3e04241e922d0ecf0b1ea8c5 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Wed, 27 Jul 2022 21:03:44 +0000 Subject: [PATCH] Fix panics in search_by_apub_id() (fixes #2371) (#2373) --- crates/apub/src/fetcher/search.rs | 8 +++++--- crates/apub/src/fetcher/webfinger.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/apub/src/fetcher/search.rs b/crates/apub/src/fetcher/search.rs index 1622e451d..00fbf67fe 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 8dda8ae1b..80dd3bc6e 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