diff --git a/bookmarks/services/auto_tagging.py b/bookmarks/services/auto_tagging.py index 2608761..840745a 100644 --- a/bookmarks/services/auto_tagging.py +++ b/bookmarks/services/auto_tagging.py @@ -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("#") diff --git a/bookmarks/tests/test_auto_tagging.py b/bookmarks/tests/test_auto_tagging.py index 320003f..b4213a1 100644 --- a/bookmarks/tests/test_auto_tagging.py +++ b/bookmarks/tests/test_auto_tagging.py @@ -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