Skip to content

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

fix: img data is not removed on editing the note

thecodrr895fd0047395
diff --git a/packages/core/__mocks__/fs.mock.js b/packages/core/__mocks__/fs.mock.js
index 146894b8a..f004d3edb 100644
--- a/packages/core/__mocks__/fs.mock.js
+++ b/packages/core/__mocks__/fs.mock.js
@@ -1,4 +1,4 @@
-const fs = {};
+var fs = {};
function hasItem(key) {
return !!fs[key];
@@ -62,6 +62,10 @@ function exists(filename) {
return hasItem(filename);
}
+async function clearFileStorage() {
+ fs = {};
+}
+
module.exports = {
writeEncrypted,
readEncrypted,
@@ -69,6 +73,7 @@ module.exports = {
downloadFile: cancellable(downloadFile),
deleteFile,
exists,
+ clearFileStorage,
};
function cancellable(operation) {
diff --git a/packages/core/__mocks__/storage.mock.js b/packages/core/__mocks__/storage.mock.js
index 18f2896a7..4927c4b3d 100644
--- a/packages/core/__mocks__/storage.mock.js
+++ b/packages/core/__mocks__/storage.mock.js
@@ -41,7 +41,11 @@ function encrypt(password, data) {
}
function decrypt(key, data) {
- if (!key || key.password === data.key.password)
+ if (
+ !key ||
+ key.password === data.key.password ||
+ key.key.password === data.key.password
+ )
return Promise.resolve(data.cipher);
else throw new Error("Wrong password");
}
diff --git a/packages/core/__tests__/notes.test.js b/packages/core/__tests__/notes.test.js
index 5f564c3b9..df0f5b66e 100644
--- a/packages/core/__tests__/notes.test.js
+++ b/packages/core/__tests__/notes.test.js
@@ -7,6 +7,7 @@ import {
LONG_TEXT,
TEST_NOTE,
TEST_NOTEBOOK,
+ IMG_CONTENT,
} from "./utils";
beforeEach(async () => {
@@ -283,3 +284,43 @@ test("grouping items where item.title is empty or undefined shouldn't throw", ()
})
).toBeTruthy();
});
+
+test("note content should not contain image base64 data after save", () =>
+ noteTest().then(async ({ db, id }) => {
+ StorageInterface.write(`_uk_@[email protected]`, {
+ key: { password: "password" },
+ });
+
+ await db.user.setUser({
+ email: "[email protected]",
+ attachmentsKey: {
+ cipher: "{}",
+ iv: "iv",
+ salt: "salt",
+ length: 100,
+ key: { password: "password" },
+ },
+ });
+
+ await db.attachments.add(
+ {
+ iv: "iv",
+ length: 100,
+ alg: "xha-stream",
+ hash: "d3eab72e94e3cd35",
+ hashType: "xxh64",
+ type: "image/jpeg",
+ chunkSize: 512,
+ filename: "hello",
+ key: {},
+ salt: "hellowrold",
+ },
+ id
+ );
+
+ await db.notes.add({ id, content: { type: "tiny", data: IMG_CONTENT } });
+ const note = db.notes.note(id);
+ const content = await note.content();
+ expect(content).not.toContain(`src="data:image/png;`);
+ expect(content).not.toContain(`src=`);
+ }));
diff --git a/packages/core/__tests__/utils/index.js b/packages/core/__tests__/utils/index.js
index 92e8516ac..72b3c999f 100644
--- a/packages/core/__tests__/utils/index.js
+++ b/packages/core/__tests__/utils/index.js
@@ -2,6 +2,7 @@ import DB from "../../api";
import StorageInterface from "../../__mocks__/storage.mock";
import dayjs from "dayjs";
import { groupArray } from "../../utils/grouping";
+import FS from "../../__mocks__/fs.mock";
const TEST_NOTEBOOK = {
title: "Test Notebook",
@@ -16,7 +17,7 @@ const TEST_NOTEBOOK2 = {
};
function databaseTest() {
- let db = new DB(StorageInterface);
+ let db = new DB(StorageInterface, null, FS);
return db.init().then(() => db);
}
@@ -33,6 +34,8 @@ var TEST_NOTE = {
},
};
+const IMG_CONTENT = `"<p>This is a note for me.j</p>\n<p><img src=\"data:image/png;base64,iVBORw0K\" class=\"attachment\" alt=\"Screenshot_20210915_102333.png\" data-mime=\"image/png\" data-hash=\"d3eab72e94e3cd35\" data-filename=\"Screenshot_20210915_102333.png\" data-size=\"68609\" style=\"float: left;\" /> &nbsp;</p>\n<p>&nbsp;</p>"`;
+
const LONG_TEXT =
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
@@ -69,6 +72,7 @@ export {
notebookTest,
noteTest,
groupedTest,
+ IMG_CONTENT,
StorageInterface,
TEST_NOTEBOOK,
TEST_NOTEBOOK2,
diff --git a/packages/core/collections/content.js b/packages/core/collections/content.js
index 77853d3cd..4fc893ad7 100644
--- a/packages/core/collections/content.js
+++ b/packages/core/collections/content.js
@@ -132,8 +132,8 @@ export default class Content extends Collection {
if (toAdd.length > 0) {
contentItem.dateEdited = Date.now();
- contentItem.data = data;
}
+ contentItem.data = data;
return contentItem;
}
}
diff --git a/packages/core/content-types/__tests__/tiny.test.js b/packages/core/content-types/__tests__/tiny.test.js
new file mode 100644
index 000000000..8b114fcf1
--- /dev/null
+++ b/packages/core/content-types/__tests__/tiny.test.js
@@ -0,0 +1,12 @@
+import { IMG_CONTENT } from "../../__tests__/utils";
+import Tiny from "../tiny";
+
+test("img src is empty after extract attachments", async () => {
+ const tiny = new Tiny(IMG_CONTENT);
+ const result = await tiny.extractAttachments(async () => {
+ return { key: "hello", metadata: {} };
+ });
+ expect(result.attachments.length).toBe(1);
+ expect(result.data).not.toContain(`src="data:image/png;`);
+ expect(result.data).not.toContain(`src=`);
+});