Skip to content

Build your personal knowledge base with Trilium Notes

fix(share): print none of a collection's leftover content on its page

StephenArg0267924ca06e
diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.ts
index 354f1e3abb..5ae1eeafae 100644
--- a/packages/trilium-core/src/share/content_renderer.spec.ts
+++ b/packages/trilium-core/src/share/content_renderer.spec.ts
@@ -38,6 +38,13 @@ describe("content_renderer", () => {
expect(result.content).toStrictEqual("<p>Protected note cannot be displayed</p>");
});
+ it("prints none of a collection's own content, which a type switch leaves behind", () => {
+ const note = buildShareNote({
+ type: "book", mime: "", content: "<script>alert(1)</script><p>Was a code note</p>"
+ });
+ expect(getContent(note)).toMatchObject({ isEmpty: true, content: "" });
+ });
+
describe("Text note", () => {
it("parses simple note", () => {
const content = trimIndentation`\
diff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.ts
index 90310cc460..4e865c82ad 100644
--- a/packages/trilium-core/src/share/content_renderer.ts
+++ b/packages/trilium-core/src/share/content_renderer.ts
@@ -533,7 +533,10 @@ export function getContent(note: SNote | BNote, options: ShareRenderOptions = {}
&& SHARE_HOSTED_VIEW_TYPES.includes(getViewType(note) ?? "")) {
renderCollectionView(result, note, options);
} else if (note.type === "book") {
+ // A collection shows its child notes. What its content still holds from a type it was
+ // switched from is never written into the page, which prints it as HTML.
result.isEmpty = true;
+ result.content = "";
} else if (note.type === "webView") {
renderWebView(note, result);
} else if ([ "noteMap", "relationMap", "render" ].includes(note.type)) {