From fd067713d7d9b47d104bd9cf8e2dd14fd3596aa4 Mon Sep 17 00:00:00 2001 From: silverpill Date: Sun, 1 May 2022 11:27:56 +0000 Subject: [PATCH] Allow to search for usernames containing "-" character --- src/mastodon_api/search/helpers.rs | 3 ++- src/models/posts/mentions.rs | 5 +++-- src/webfinger/views.rs | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mastodon_api/search/helpers.rs b/src/mastodon_api/search/helpers.rs index 537cbc2..391add1 100644 --- a/src/mastodon_api/search/helpers.rs +++ b/src/mastodon_api/search/helpers.rs @@ -32,7 +32,8 @@ enum SearchQuery { fn parse_profile_query(query: &str) -> Result<(String, Option), ValidationError> { - let acct_regexp = Regex::new(r"^@?(?P\w+)(@(?P[\w\.-]+))?$").unwrap(); + // See also: USERNAME_RE in models::profiles::validators + let acct_regexp = Regex::new(r"^@?(?P[\w\.-]+)(@(?P[\w\.-]+))?$").unwrap(); let acct_caps = acct_regexp.captures(query) .ok_or(ValidationError("invalid search query"))?; let username = acct_caps.name("user") diff --git a/src/models/posts/mentions.rs b/src/models/posts/mentions.rs index 65ce09d..50d7915 100644 --- a/src/models/posts/mentions.rs +++ b/src/models/posts/mentions.rs @@ -8,8 +8,9 @@ use crate::errors::{DatabaseError, ValidationError}; use crate::models::profiles::queries::get_profiles_by_accts; use crate::models::profiles::types::DbActorProfile; -const MENTION_RE: &str = r"@?(?P\w+)@(?P.+)"; -const MENTION_SEARCH_RE: &str = r"(?m)(?P^|\s)@(?P\w+)@(?P\S+)"; +// See also: USERNAME_RE in models::profiles::validators +const MENTION_RE: &str = r"@?(?P[\w\.-]+)@(?P.+)"; +const MENTION_SEARCH_RE: &str = r"(?m)(?P^|\s)@(?P[\w\.-]+)@(?P\S+)"; const MENTION_SEARCH_SECONDARY_RE: &str = r"^(?P[\w\.-]+\w)(?P(\.|
|\.
)?)$"; /// Finds everything that looks like a mention diff --git a/src/webfinger/views.rs b/src/webfinger/views.rs index 6fdf39e..c1ad192 100644 --- a/src/webfinger/views.rs +++ b/src/webfinger/views.rs @@ -22,7 +22,8 @@ async fn get_user_info( ) -> Result { // Parse 'acct' URI // https://datatracker.ietf.org/doc/html/rfc7565#section-7 - let uri_regexp = Regex::new(r"acct:(?P[\w\.]+)@(?P.+)").unwrap(); + // See also: USERNAME_RE in models::profiles::validators + let uri_regexp = Regex::new(r"acct:(?P[\w\.-]+)@(?P.+)").unwrap(); let uri_caps = uri_regexp.captures(&query_params.resource) .ok_or(ValidationError("invalid query target"))?; let username = uri_caps.name("user")