From d213e4ab57b71aa0ca887328b5f00291a27d8a9b Mon Sep 17 00:00:00 2001 From: Luis Orozco <6557454+innocuo@users.noreply.github.com> Date: Mon, 6 May 2019 15:25:14 -0500 Subject: [PATCH 1/3] All: Fixed: Prevents notes with no title to break after synchronize (#1472) Tests to confirm serialize/unserialize don't change body and title check if item title exists, otherwise display default title. added test checking serializing/unserializing Folders don't modify data --- CliClient/tests/models_BaseItem.js | 15 +++++++++++++ CliClient/tests/models_Note.js | 27 ++++++++++++++++++++++++ ReactNativeClient/lib/models/BaseItem.js | 4 ++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/CliClient/tests/models_BaseItem.js b/CliClient/tests/models_BaseItem.js index e53474d32..9c274e0ff 100644 --- a/CliClient/tests/models_BaseItem.js +++ b/CliClient/tests/models_BaseItem.js @@ -47,5 +47,20 @@ describe('models_BaseItem', function() { expect('ignore_me' in unserialized).toBe(false); })); + + it('should not modify title when unserializing', asyncTest(async () => { + let folder1 = await Folder.save({ title: "" }); + let folder2 = await Folder.save({ title: "folder1" }); + + let serialized1 = await Folder.serialize(folder1); + let unserialized1 = await Folder.unserialize(serialized1); + + expect(unserialized1.title).toBe(folder1.title); + + let serialized2 = await Folder.serialize(folder2); + let unserialized2 = await Folder.unserialize(serialized2); + + expect(unserialized2.title).toBe(folder2.title); + })); }); \ No newline at end of file diff --git a/CliClient/tests/models_Note.js b/CliClient/tests/models_Note.js index 3a9f427c1..876b337b3 100644 --- a/CliClient/tests/models_Note.js +++ b/CliClient/tests/models_Note.js @@ -86,5 +86,32 @@ describe('models_Note', function() { expect(changedNote === note1).toBe(false); expect(!!changedNote.is_todo).toBe(false); })); + + it('should serialize and unserialize without modifying data', asyncTest(async () => { + let folder1 = await Folder.save({ title: "folder1"}); + const testCases = [ + [ {title: '', body:'Body and no title\nSecond line\nThird Line', parent_id: folder1.id}, + '', 'Body and no title\nSecond line\nThird Line'], + [ {title: 'Note title', body:'Body and title', parent_id: folder1.id}, + 'Note title', 'Body and title'], + [ {title: 'Title and no body', body:'', parent_id: folder1.id}, + 'Title and no body', ''], + ] + + for (let i = 0; i < testCases.length; i++) { + const t = testCases[i]; + + const input = t[0]; + const expectedTitle = t[1]; + const expectedBody = t[1]; + + let note1 = await Note.save(input); + let serialized = await Note.serialize(note1); + let unserialized = await Note.unserialize( serialized); + + expect(unserialized.title).toBe(input.title); + expect(unserialized.body).toBe(input.body); + } + })); }); \ No newline at end of file diff --git a/ReactNativeClient/lib/models/BaseItem.js b/ReactNativeClient/lib/models/BaseItem.js index 761800434..15c241289 100644 --- a/ReactNativeClient/lib/models/BaseItem.js +++ b/ReactNativeClient/lib/models/BaseItem.js @@ -279,7 +279,7 @@ class BaseItem extends BaseModel { let temp = []; - if (output.title) temp.push(output.title); + if (typeof output.title === "string") temp.push(output.title); if (output.body) temp.push(output.body); if (output.props.length) temp.push(output.props.join("\n")); @@ -644,7 +644,7 @@ class BaseItem extends BaseModel { static displayTitle(item) { if (!item) return ''; - return !!item.encryption_applied ? '🔑 ' + _('Encrypted') : item.title + ''; + return !!item.encryption_applied ? '🔑 ' + _('Encrypted') : (!!item.title)? item.title + '' : Note.defaultTitle(item); } static async markAllNonEncryptedForSync() { From f136f40fdcf60aba3e679e6c8527473c9bdd28de Mon Sep 17 00:00:00 2001 From: Caleb John Date: Mon, 6 May 2019 14:26:34 -0600 Subject: [PATCH 2/3] Doc: Update readme to warn about restarting the editor for userstyle (#1487) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf1b0dd33..be5a547d6 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ It is generally recommended to enter the notes as Markdown as it makes the notes ## Custom CSS -Rendered markdown can be customized by placing a userstyle file in the profile directory `~/.config/joplin-desktop/userstyle.css` (This path might be different on your device - check at the top of the Config screen for the exact path). This file supports standard CSS syntax. Note that this file is used only when display the notes, **not when printing or exporting to PDF**. This is because printing has a lot more restrictions (for example, printing white text over a black background is usually not wanted), so special rules are applied to make it look good when printing, and a userstyle.css would interfer with that. +Rendered markdown can be customized by placing a userstyle file in the profile directory `~/.config/joplin-desktop/userstyle.css` (This path might be different on your device - check at the top of the Config screen for the exact path). This file supports standard CSS syntax. Joplin ***must*** be restarted for the new css to be applied, please ensure that Joplin is not closing to the tray, but is actually exiting. Note that this file is used only when display the notes, **not when printing or exporting to PDF**. This is because printing has a lot more restrictions (for example, printing white text over a black background is usually not wanted), so special rules are applied to make it look good when printing, and a userstyle.css would interfer with that. # Searching From 5934f2f08e8fdd85036e8b0fbecbb0c0de8e39f5 Mon Sep 17 00:00:00 2001 From: Luis Orozco <6557454+innocuo@users.noreply.github.com> Date: Mon, 6 May 2019 15:30:04 -0500 Subject: [PATCH 3/3] Desktop: Fixes #355: Resets the undo manager when creating new notes (#1495) --- ElectronClient/app/gui/NoteText.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 27396f954..5c07733f5 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -501,7 +501,7 @@ class NoteTextComponent extends React.Component { // 2. It resets the undo manager - fixes https://github.com/laurent22/joplin/issues/355 // Note: calling undoManager.reset() doesn't work try { - this.editor_.editor.getSession().setValue(note ? note.body : ''); + this.editor_.editor.getSession().setValue(note && note.body? note.body : ''); } catch (error) { if (error.message === "Cannot read property 'match' of undefined") { // The internals of Ace Editor throws an exception when creating a new note,