aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared/import-export/importer.test.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-12-24 12:10:02 +0200
committerGitHub <noreply@github.com>2025-12-24 10:10:02 +0000
commit3408e6e4854dc79b963eef455e9a69231de3cd28 (patch)
tree0f5c9b218bac15a1a2e90e70186b779b8946f0d9 /packages/shared/import-export/importer.test.ts
parente336513fad5bd5597c890b02deb20b4519013881 (diff)
downloadkarakeep-3408e6e4854dc79b963eef455e9a69231de3cd28.tar.zst
fix: handle empty folder names in HTML bookmark imports (#2300)
When importing bookmarks from an HTML file, empty H3 tags (folder names) are now replaced with "Unnamed" to prevent import failures. Fixes #2299 Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Mohamed Bassem <MohamedBassem@users.noreply.github.com>
Diffstat (limited to 'packages/shared/import-export/importer.test.ts')
-rw-r--r--packages/shared/import-export/importer.test.ts82
1 files changed, 82 insertions, 0 deletions
diff --git a/packages/shared/import-export/importer.test.ts b/packages/shared/import-export/importer.test.ts
index 48cd1204..7e381f20 100644
--- a/packages/shared/import-export/importer.test.ts
+++ b/packages/shared/import-export/importer.test.ts
@@ -402,6 +402,88 @@ describe("importBookmarksFromFile", () => {
expect(updateBookmarkTags).toHaveBeenCalledTimes(2);
});
+ it("handles HTML bookmarks with empty folder names", async () => {
+ const htmlContent = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
+<TITLE>Bookmarks</TITLE>
+<H1>Bookmarks</H1>
+<DL><p>
+ <DT><H3 ADD_DATE="1765995928" LAST_MODIFIED="1765995928">Bluetooth Fernbedienung</H3>
+ <DL><p>
+ <DT><H3 ADD_DATE="1765995928" LAST_MODIFIED="0"></H3>
+ <DL><p>
+ <DT><A HREF="https://www.example.com/product.html" ADD_DATE="1593444456">Example Product</A>
+ </DL><p>
+ </DL><p>
+</DL><p>`;
+
+ const mockFile = {
+ text: vi.fn().mockResolvedValue(htmlContent),
+ } as unknown as File;
+
+ const createdLists: { name: string; icon: string; parentId?: string }[] =
+ [];
+ const createList = vi.fn(
+ async (input: { name: string; icon: string; parentId?: string }) => {
+ createdLists.push(input);
+ return {
+ id: `${input.parentId ? input.parentId + "/" : ""}${input.name}`,
+ };
+ },
+ );
+
+ const createdBookmarks: ParsedBookmark[] = [];
+ const createBookmark = vi.fn(async (bookmark: ParsedBookmark) => {
+ createdBookmarks.push(bookmark);
+ return {
+ id: `bookmark-${createdBookmarks.length}`,
+ alreadyExists: false,
+ };
+ });
+
+ const res = await importBookmarksFromFile({
+ file: mockFile,
+ source: "html",
+ rootListName: "HTML Import",
+ deps: {
+ createList,
+ createBookmark,
+ addBookmarkToLists: vi.fn(),
+ updateBookmarkTags: vi.fn(),
+ createImportSession: vi.fn(async () => ({ id: "session-1" })),
+ },
+ });
+
+ expect(res.counts).toEqual({
+ successes: 1,
+ failures: 0,
+ alreadyExisted: 0,
+ total: 1,
+ });
+
+ // Verify that the empty folder name was replaced with "Unnamed"
+ expect(createdLists).toEqual([
+ { name: "HTML Import", icon: "⬆️" },
+ { name: "Bluetooth Fernbedienung", parentId: "HTML Import", icon: "📁" },
+ {
+ name: "Unnamed",
+ parentId: "HTML Import/Bluetooth Fernbedienung",
+ icon: "📁",
+ },
+ ]);
+
+ // Verify the bookmark was created and assigned to the correct path
+ expect(createdBookmarks).toHaveLength(1);
+ expect(createdBookmarks[0]).toMatchObject({
+ title: "Example Product",
+ content: {
+ type: "link",
+ url: "https://www.example.com/product.html",
+ },
+ tags: [],
+ });
+ });
+
it("parses mymind CSV export correctly", async () => {
const mymindCsv = `id,type,title,url,content,note,tags,created
1pYm0O0hY4WnmKN,WebPage,mymind,https://access.mymind.com/everything,,,"Wellness,Self-Improvement,Psychology",2024-12-04T23:02:10Z