Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bookmark import issue with missing folder names #598

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

LeonKohli
Copy link

🐛 Fix importing bookmarks from HTML with unnamed folders

Description

This pull request addresses an issue where importing bookmarks from an HTML file fails when a bookmark folder has no name. The current implementation fails the creation of collections for unnamed folders, leading to an infinite loader and no, or missing bookmarks.

Example

Here's an example of an HTML snippet that demonstrates the issue:

<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
     It will be read and overwritten.
     DO NOT EDIT! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
    <DT><H3 ADD_DATE="1715187970" LAST_MODIFIED="0" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks bar</H3>
    <DL><p>
        <DT><H3 ADD_DATE="1715188017" LAST_MODIFIED="0"></H3>
        <DL><p>
            <DT><H3 ADD_DATE="1715188017" LAST_MODIFIED="0">Photos</H3>
            <DL><p>
                <DT><A HREF="https://www.istockphoto.com/de" ADD_DATE="1690043474">Bilder Kaufen, Stockfotos, Vektorbilder, Footage - iStock</A>
                ...

In this example, the bookmark folder with the name "Photos" is nested inside an unnamed folder. The current implementation fails to import all bookmarks and creates and infinite loader and wont import any bookmarks up to this point in the html.

Solution

The proposed solution is to handle the case when a bookmark folder has no name by assigning a default name, such as "Untitled Collection". This ensures that the collection is still created and all bookmarks will be imported correctly.

The changes are made in the processBookmarks function in the importFromHTMLFile.ts file. Here's the relevant code snippet:

if (collectionName) {
  const collectionNameContent = (collectionName.children[0] as TextNode)?.content;
  if (collectionNameContent) {
    collectionId = await createCollection(
      userId,
      collectionNameContent,
      parentCollectionId
    );
  } else {
    // Handle the case when the collection name is empty
    collectionId = await createCollection(
      userId,
      "Untitled Collection",
      parentCollectionId
    );
  }
}

When the collectionNameContent is falsy (i.e., the folder has no name), a collection with the name "Untitled Collection" is created instead of failing the collection creation altogether.

Benefits

  • Improves the reliability of importing bookmarks from HTML files.
  • Ensures that all bookmarks are imported, even if they are inside unnamed folders.

@CLAassistant
Copy link

CLAassistant commented May 8, 2024

CLA assistant check
All committers have signed the CLA.

@LeonKohli LeonKohli changed the base branch from main to dev May 8, 2024 20:14
@daniel31x13
Copy link
Member

Hello sorry for the late reply and thank you for the PR, gonna merge this soon after I implement the upcoming features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants