Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(share): keep query stripping to internal reference links
matt wilkie19d7ca4dc1f9
diff --git a/apps/server/src/share/content_renderer.spec.ts b/apps/server/src/share/content_renderer.spec.tsindex 2000f53992..f13dd965d2 100644--- a/apps/server/src/share/content_renderer.spec.ts+++ b/apps/server/src/share/content_renderer.spec.ts@@ -344,6 +344,16 @@ describe("content_renderer", () => {expect(content).toStrictEqual("<p>Foo</p>");});+ it("does not treat an external URL's query string as a note ID", () => {+ const target = buildShareNote({ id: "extIdTarget1", title: "Target" });+ const note = buildShareNote({+ id: "note",+ content: `<p><a class="reference-link" href="https://example.com/${target.noteId}?x=1">text</a></p>`+ });+ const result = getContent(note);+ expect(result.content).toStrictEqual("<p>text</p>");+ });+it("properly escapes note title", () => {buildShareNote({id: "MSkxxCFbBsYP",diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.tsindex 0b097c9209..8b1882a058 100644--- a/apps/server/src/share/content_renderer.ts+++ b/apps/server/src/share/content_renderer.ts@@ -618,7 +618,10 @@ function cleanUpReferenceLinks(linkEl: HTMLElement, href: string, getNote: GetNo}// `handleAttachmentLink()` removes the `href` of a link whose target is missing.- const noteId = linkEl.hasAttribute("href") ? getNoteIdFromLink(href) : "";+ let noteId = "";+ if (linkEl.hasAttribute("href")) {+ noteId = href.startsWith("#") ? getNoteIdFromLink(href) : (href.split("/").at(-1) ?? "");+ }const note = noteId ? getNote(noteId) : undefined;if (!note) {// If a note is not found, simply replace it with a text.