Web user signup: remove leading and trailing dots from domains

nostr
Ryan Barrett 2023-08-18 13:30:26 -07:00
rodzic 04bacf0361
commit ebb0a6c154
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 12 dodań i 2 usunięć

Wyświetl plik

@ -476,6 +476,12 @@ class WebTest(TestCase):
self.assertEqual('☃.net', user.key.id())
self.assert_entities_equal(user, Web.get_by_id('☃.net'))
def test_get_or_create_scripts_leading_trailing_dots(self, *_):
user = Web.get_or_create('..foo.bar.')
self.assertEqual('foo.bar', user.key.id())
self.assert_entities_equal(user, Web.get_by_id('foo.bar'))
self.assertIsNone(Web.get_by_id('..foo.bar.'))
def test_bad_source_url(self, *mocks):
orig_count = Object.query().count()

8
web.py
Wyświetl plik

@ -73,8 +73,12 @@ class Web(User, Protocol):
@classmethod
def get_or_create(cls, id, **kwargs):
"""Lower cases id (domain), then passes through to :meth:`User.get_or_create`."""
return super().get_or_create(id.lower(), **kwargs)
"""Normalizes domain, then passes through to :meth:`User.get_or_create`.
Normalizing currently consists of lower casing and removing leading and
trailing dots.
"""
return super().get_or_create(id.lower().strip('.'), **kwargs)
def web_url(self):
"""Returns this user's web URL aka web_url, eg 'https://foo.com/'."""