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
This commit is contained in:
Grafcube 2023-04-03 01:02:54 +05:30 committed by GitHub
parent c56f526914
commit 813d7943e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,7 +71,12 @@ where
T: Clone, T: Clone,
{ {
// TODO: would be nice if we could implement this without regex and remove the dependency // 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())) // 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)?; .map_err(Error::other)?;
Ok(regex Ok(regex
.captures(query) .captures(query)