Fix normalized URL not being generated in bookmark import (#1202)

This commit is contained in:
Sascha Ißbrücker
2025-10-11 09:57:14 +02:00
committed by GitHub
parent 6ac8ce6a7b
commit 8b98a335d4
2 changed files with 18 additions and 1 deletions

View File

@@ -8,7 +8,7 @@ from django.utils import timezone
from bookmarks.models import Bookmark, Tag from bookmarks.models import Bookmark, Tag
from bookmarks.services import tasks from bookmarks.services import tasks
from bookmarks.services.parser import parse, NetscapeBookmark from bookmarks.services.parser import parse, NetscapeBookmark
from bookmarks.utils import parse_timestamp from bookmarks.utils import normalize_url, parse_timestamp
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -181,6 +181,7 @@ def _import_batch(
bookmarks_to_update, bookmarks_to_update,
[ [
"url", "url",
"url_normalized",
"date_added", "date_added",
"date_modified", "date_modified",
"unread", "unread",
@@ -234,6 +235,7 @@ def _copy_bookmark_data(
netscape_bookmark: NetscapeBookmark, bookmark: Bookmark, options: ImportOptions netscape_bookmark: NetscapeBookmark, bookmark: Bookmark, options: ImportOptions
): ):
bookmark.url = netscape_bookmark.href bookmark.url = netscape_bookmark.href
bookmark.url_normalized = normalize_url(bookmark.url)
if netscape_bookmark.date_added: if netscape_bookmark.date_added:
bookmark.date_added = parse_timestamp(netscape_bookmark.date_added) bookmark.date_added = parse_timestamp(netscape_bookmark.date_added)
else: else:

View File

@@ -409,6 +409,21 @@ class ImporterTestCase(TestCase, BookmarkFactoryMixin, ImportTestMixin):
self.assertEqual(import_result.success, 0) self.assertEqual(import_result.success, 0)
self.assertEqual(import_result.failed, 2) self.assertEqual(import_result.failed, 2)
def test_generate_normalized_url(self):
html_tags = [
BookmarkHtmlTag(href="https://example.com/?z=1&a=2#"),
BookmarkHtmlTag(
href="foo.bar"
), # invalid URL, should be skipped without error
]
import_html = self.render_html(tags=html_tags)
import_netscape_html(import_html, self.get_or_create_test_user())
self.assertEqual(Bookmark.objects.count(), 1)
self.assertEqual(
Bookmark.objects.all()[0].url_normalized, "https://example.com?a=2&z=1"
)
def test_private_flag(self): def test_private_flag(self):
# does not map private flag if not enabled in options # does not map private flag if not enabled in options
test_html = self.render_html( test_html = self.render_html(