]> Untitled Git - lemmy.git/commitdiff
Fix panics in search_by_apub_id() (fixes #2371) (#2373)
authorNutomic <me@nutomic.com>
Wed, 27 Jul 2022 21:03:44 +0000 (21:03 +0000)
committerGitHub <noreply@github.com>
Wed, 27 Jul 2022 21:03:44 +0000 (17:03 -0400)
crates/apub/src/fetcher/search.rs
crates/apub/src/fetcher/webfinger.rs

index 1622e451df6f463ddeb288f20bb27de2a7e885e8..00fbf67fe8795ce71ca3eaac889664d95574ca4d 100644 (file)
@@ -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::<ApubPerson>(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::<ApubCommunity>(identifier, context, request_counter).await?;
           Ok(SearchableObjects::Community(
index 8dda8ae1b26d0b672f7ac49255841d63b56cd735..80dd3bc6ebc8129dc961a6bdc07e778b6b0da84e 100644 (file)
@@ -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