Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

feat: Use the same decoder that JSDom uses to encode

AverageHelper0344467cb766
diff --git a/lib/api/controllers/migration/importFromHTMLFile.ts b/lib/api/controllers/migration/importFromHTMLFile.ts
index fb87dd02..12ee044a 100644
--- a/lib/api/controllers/migration/importFromHTMLFile.ts
+++ b/lib/api/controllers/migration/importFromHTMLFile.ts
@@ -1,6 +1,7 @@
import { prisma } from "@/lib/api/db";
import createFolder from "@/lib/api/storage/createFolder";
import { JSDOM } from "jsdom";
+import { decodeHTML, DecodingMode } from "entities";
import { parse, Node, Element, TextNode } from "himalaya";
import { hasPassedLimit } from "../../verifyCapacity";
@@ -33,7 +34,6 @@ export default async function importFromHTMLFile(
const processedArray = processNodes(jsonData);
for (const item of processedArray) {
- console.log(item);
await processBookmarks(userId, item as Element);
}
@@ -81,15 +81,17 @@ async function processBookmarks(
} else if (item.type === "element" && item.tagName === "a") {
// process link
- const linkUrl = item?.attributes
- .find((e) => e.key.toLowerCase() === "href")
- ?.value.replace(/&/g, "&"); // Replace "&" with "&" to get around parser bug
+ const rawLinkUrl = item?.attributes.find(
+ (e) => e.key.toLowerCase() === "href"
+ )?.value;
+ const linkUrl = decodeEntities(rawLinkUrl);
const linkName = (
item?.children.find((e) => e.type === "text") as TextNode
)?.content;
const linkTags = item?.attributes
.find((e) => e.key === "tags")
- ?.value.split(",");
+ ?.value.split(",")
+ .map(decodeEntities);
// set date if available
const linkDateValue = item?.attributes.find(
@@ -290,3 +292,7 @@ function processNodes(nodes: Node[]) {
nodes.forEach(findAndProcessDL);
return nodes;
}
+
+function decodeEntities(encoded: string | undefined): string {
+ return decodeHTML(encoded ?? "", DecodingMode.Attribute);
+}
diff --git a/yarn.lock b/yarn.lock
index 71ba16b2..d2d3e352 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2556,9 +2556,9 @@ camelcase-css@^2.0.1:
integrity sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==
caniuse-lite@^1.0.30001406, caniuse-lite@^1.0.30001464, caniuse-lite@^1.0.30001489:
- version "1.0.30001502"
- resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001502.tgz#f7e4a76eb1d2d585340f773767be1fefc118dca8"
- integrity sha512-AZ+9tFXw1sS0o0jcpJQIXvFTOB/xGiQ4OQ2t98QX3NDn2EZTSRBC801gxrsGgViuq2ak/NLkNgSNEPtCr5lfKg==
+ version "1.0.30001690"
+ resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001690.tgz"
+ integrity sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w==
caseless@~0.12.0:
version "0.12.0"