Improve error handling for auto tagging (#855)

This commit is contained in:
Sascha Ißbrücker 2024-09-24 17:26:01 +02:00 committed by GitHub
parent c93709b549
commit 52400feacf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View file

@ -7,6 +7,9 @@ def get_tags(script: str, url: str):
parsed_url = urlparse(url.lower())
result = set()
if not parsed_url.hostname:
return result
for line in script.lower().split("\n"):
if "#" in line:
i = line.index("#")

View file

@ -14,6 +14,20 @@ class AutoTaggingTestCase(TestCase):
self.assertEqual(tags, {"example"})
def test_auto_tag_by_domain_handles_invalid_urls(self):
script = """
example.com example
test.com test
"""
url = "https://"
tags = auto_tagging.get_tags(script, url)
self.assertEqual(tags, set([]))
url = "example.com"
tags = auto_tagging.get_tags(script, url)
self.assertEqual(tags, set([]))
def test_auto_tag_by_domain_works_with_port(self):
script = """
example.com example