Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: fix `Cannot read properties of undefined (reading 'startsWith')` error on export

Abdullah Atta1e6f6ab47764
diff --git a/packages/core/src/content-types/tiptap.ts b/packages/core/src/content-types/tiptap.ts
index f38f0109c..3e466c5a8 100644
--- a/packages/core/src/content-types/tiptap.ts
+++ b/packages/core/src/content-types/tiptap.ts
@@ -184,7 +184,7 @@ export class Tiptap {
this.data = new HTMLRewriter({
ontag: (name, attr) => {
const href = attr[ATTRIBUTES.href];
- if (name === "a" && href.startsWith("nn://")) {
+ if (name === "a" && href && href.startsWith("nn://")) {
const link = resolve(href);
if (!link) return;
attr[ATTRIBUTES.href] = link;
@@ -244,7 +244,10 @@ export class Tiptap {
if (types.includes("internalLinks")) {
result.internalLinks.push(
...findAll(
- (e) => e.tagName === "a" && e.attribs.href.startsWith("nn://"),
+ (e) =>
+ e.tagName === "a" &&
+ !!e.attribs.href &&
+ e.attribs.href.startsWith("nn://"),
document.childNodes
)
.map((e) => parseInternalLink(e.attribs.href))
diff --git a/packages/core/src/utils/internal-link.ts b/packages/core/src/utils/internal-link.ts
index b26e1c8ee..80ee1edc4 100644
--- a/packages/core/src/utils/internal-link.ts
+++ b/packages/core/src/utils/internal-link.ts
@@ -66,7 +66,7 @@ export function parseInternalLink(link: string): InternalLink | undefined {
}
export function isInternalLink(link: string) {
- return link.startsWith("nn://");
+ return link && link.startsWith("nn://");
}
function isValidInternalType(type: string): type is InternalLinkType {