From 256ffe39f2ee11702432d616743b4448fdf74def Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 27 Jun 2025 14:22:08 +0300 Subject: [PATCH] fix(server): saving revision of note with empty title not supported (closes #6103) --- .../src/becca/entities/brevision.spec.ts | 22 +++++++++++++++++++ apps/server/src/becca/entities/brevision.ts | 6 ++--- 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 apps/server/src/becca/entities/brevision.spec.ts diff --git a/apps/server/src/becca/entities/brevision.spec.ts b/apps/server/src/becca/entities/brevision.spec.ts new file mode 100644 index 000000000..176ee66c0 --- /dev/null +++ b/apps/server/src/becca/entities/brevision.spec.ts @@ -0,0 +1,22 @@ +import BRevision from "./brevision.js"; + +describe("Revision", () => { + it("handles note with empty title properly", () => { + const revision = new BRevision({ + revisionId: "4omM5OvlLhOw", + noteId: "WHMg7iFCRG3Z", + type: "text", + mime: "text/html", + isProtected: false, + title: "", + blobId: "", + dateLastEdited: "2025-06-27 14:10:39.688+0300", + dateCreated: "2025-06-27 14:10:39.688+0300", + utcDateLastEdited: "2025-06-27 14:10:39.688+0300", + utcDateCreated: "2025-06-27 14:10:39.688+0300", + utcDateModified: "2025-06-27 14:10:39.688+0300" + }); + const pojo = revision.getPojo(); + expect(pojo.title).toBeDefined(); + }); +}); diff --git a/apps/server/src/becca/entities/brevision.ts b/apps/server/src/becca/entities/brevision.ts index dcd3103f2..83767a3b2 100644 --- a/apps/server/src/becca/entities/brevision.ts +++ b/apps/server/src/becca/entities/brevision.ts @@ -192,7 +192,7 @@ class BRevision extends AbstractBeccaEntity { type: this.type, mime: this.mime, isProtected: this.isProtected, - title: this.title || undefined, + title: this.title, blobId: this.blobId, dateLastEdited: this.dateLastEdited, dateCreated: this.dateCreated, @@ -211,10 +211,10 @@ class BRevision extends AbstractBeccaEntity { if (pojo.isProtected) { if (protectedSessionService.isProtectedSessionAvailable()) { - pojo.title = protectedSessionService.encrypt(this.title) || undefined; + pojo.title = protectedSessionService.encrypt(this.title) ?? ""; } else { // updating protected note outside of protected session means we will keep original ciphertexts - delete pojo.title; + pojo.title = ""; } }