Ignore tags that exceed length limit during import (#1153)

This commit is contained in:
Sascha Ißbrücker
2025-08-10 15:05:10 +02:00
committed by GitHub
parent 5cc8c9c010
commit 1e56b0e6f3
2 changed files with 33 additions and 0 deletions

View File

@@ -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)

View File

@@ -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"""
<DT><A HREF="https://example.com" TAGS="{long_tag}, {valid_tag}">Example.com</A>
<DD>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(