diff --git a/bookmarks/services/importer.py b/bookmarks/services/importer.py index 41fda08..50acaeb 100644 --- a/bookmarks/services/importer.py +++ b/bookmarks/services/importer.py @@ -96,6 +96,13 @@ def _create_missing_tags(netscape_bookmarks: List[NetscapeBookmark], user: User) for netscape_bookmark in netscape_bookmarks: for tag_name in netscape_bookmark.tag_names: + # Skip tag names that exceed the maximum allowed length + if len(tag_name) > 64: + logger.warning( + f"Ignoring tag '{tag_name}' (length {len(tag_name)}) as it exceeds maximum length of 64 characters" + ) + continue + tag = tag_cache.get(tag_name) if not tag: tag = Tag(name=tag_name, owner=user) diff --git a/bookmarks/tests/test_importer.py b/bookmarks/tests/test_importer.py index 996e9b9..49949b3 100644 --- a/bookmarks/tests/test_importer.py +++ b/bookmarks/tests/test_importer.py @@ -366,6 +366,32 @@ class ImporterTestCase(TestCase, BookmarkFactoryMixin, ImportTestMixin): self.assertListEqual(tag_names, ["tag-1", "tag-2", "tag-3"]) + def test_ignore_long_tag_names(self): + long_tag = "a" * 65 + valid_tag = "valid-tag" + + test_html = self.render_html( + tags_html=f""" +
Example.com +
Example.com + """ + ) + result = import_netscape_html(test_html, self.get_or_create_test_user()) + + # Import should succeed + self.assertEqual(result.success, 1) + self.assertEqual(result.failed, 0) + + # Only the valid tag should be created + tags = Tag.objects.all() + self.assertEqual(len(tags), 1) + self.assertEqual(tags[0].name, valid_tag) + + # Bookmark should only have the valid tag assigned + bookmark = Bookmark.objects.get(url="https://example.com") + bookmark_tag_names = [tag.name for tag in bookmark.tags.all()] + self.assertEqual(bookmark_tag_names, [valid_tag]) + @disable_logging def test_validate_empty_or_missing_bookmark_url(self): test_html = self.render_html(