Skip to content

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

core: tagging an empty note should not create a content item

Abdullah Atta7ff5f0001c99
diff --git a/packages/core/__tests__/content.test.js b/packages/core/__tests__/content.test.js
index 5322be31c..9f5e81480 100644
--- a/packages/core/__tests__/content.test.js
+++ b/packages/core/__tests__/content.test.js
@@ -32,3 +32,15 @@ test("adding a deleted content should not throw", () =>
})
).resolves.toBeUndefined();
}));
+
+test("tagging an empty note should not create an invalid content item", () =>
+ databaseTest().then(async (db) => {
+ const id = await db.notes.add({ title: "Hello" });
+ const contentId = await db.notes.note(id)._note.contentId;
+ expect(contentId).toBeUndefined();
+ expect(await db.content.all()).toHaveLength(0);
+
+ await db.notes.note(id).tag("tag1");
+
+ expect(await db.content.all()).toHaveLength(0);
+ }));
diff --git a/packages/core/src/collections/notes.js b/packages/core/src/collections/notes.js
index 596a6ada0..822146764 100644
--- a/packages/core/src/collections/notes.js
+++ b/packages/core/src/collections/notes.js
@@ -106,7 +106,7 @@ export default class Notes extends Collection {
if (oldNote) note.dateEdited = Date.now();
}
- if (noteArg.localOnly !== undefined) {
+ if (note.contentId && noteArg.localOnly !== undefined) {
await this._db.content.add({
id: note.contentId,
localOnly: !!noteArg.localOnly