From 813d7943e1e0470d9ad8a2b6baac574e3ae568f2 Mon Sep 17 00:00:00 2001 From: Grafcube Date: Mon, 3 Apr 2023 01:02:54 +0530 Subject: [PATCH] Change username regex in webfinger (#34) * Change username regex in webfinger Changes the regex used for username in `extract_webfinger_name` to include additional characters like '.' and '-'. This is the same regex used in Mastodon. * Add link to Mastodon regex --- src/fetch/webfinger.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/fetch/webfinger.rs b/src/fetch/webfinger.rs index 8160e36..655598b 100644 --- a/src/fetch/webfinger.rs +++ b/src/fetch/webfinger.rs @@ -71,8 +71,13 @@ where T: Clone, { // TODO: would be nice if we could implement this without regex and remove the dependency - let regex = Regex::new(&format!("^acct:([a-zA-Z0-9_]{{3,}})@{}$", data.domain())) - .map_err(Error::other)?; + // Regex taken from Mastodon - + // https://github.com/mastodon/mastodon/blob/2b113764117c9ab98875141bcf1758ba8be58173/app/models/account.rb#L65 + let regex = Regex::new(&format!( + "^acct:((?i)[a-z0-9_]+([a-z0-9_\\.-]+[a-z0-9_]+)?)@{}$", + data.domain() + )) + .map_err(Error::other)?; Ok(regex .captures(query) .and_then(|c| c.get(1))