From 54f27519df0d71f5bc2666e97dd006ce4bd16024 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 6 Jan 2021 16:01:13 -0800 Subject: [PATCH] Fixes username regex --- bookwyrm/models/user.py | 1 + bookwyrm/utils/regex.py | 4 ++-- bookwyrm/views.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 4cbe387f..afba0b3a 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -170,6 +170,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): def save(self, *args, **kwargs): ''' populate fields for new local users ''' # this user already exists, no need to populate fields + print(self.username) if not self.local and not re.match(regex.full_username, self.username): # generate a username that uses the domain (webfinger format) actor_parts = urlparse(self.remote_id) diff --git a/bookwyrm/utils/regex.py b/bookwyrm/utils/regex.py index b087b564..c818bc41 100644 --- a/bookwyrm/utils/regex.py +++ b/bookwyrm/utils/regex.py @@ -1,10 +1,10 @@ ''' defining regexes for regularly used concepts ''' domain = r'[\w_\-\.]+\.[a-z]{2,}' -localname = r'@?[a-zA-Z_\-\.0-9]+\b' +localname = r'@?[a-zA-Z_\-\.0-9]+' strict_localname = r'@[a-zA-Z_\-\.0-9]+' username = r'%s(@%s)?' % (localname, domain) strict_username = r'\B%s(@%s)?\b' % (strict_localname, domain) -full_username = r'\B%s@%s\b' % (localname, domain) +full_username = r'%s@%s\b' % (localname, domain) # should match (BookWyrm/1.0.0; or (BookWyrm/99.1.2; bookwyrm_user_agent = r'\(BookWyrm/[0-9]+\.[0-9]+\.[0-9]+;' diff --git a/bookwyrm/views.py b/bookwyrm/views.py index f1851da8..5c5934dd 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -265,7 +265,7 @@ def search(request): return JsonResponse([r.json() for r in book_results], safe=False) # use webfinger for mastodon style account@domain.com username - if re.match(regex.full_username, query): + if re.match(r'\B%s' % regex.full_username, query): outgoing.handle_remote_webfinger(query) # do a local user search