laurent22 / joplin

Joplin - the privacy-focused note taking app with sync capabilities for Windows, macOS, Linux, Android and iOS.
https://joplinapp.org
Other
45.45k stars 4.94k forks source link

Editing an HTML note in the rich text editor removes resource links #9304

Closed personalizedrefrigerator closed 10 months ago

personalizedrefrigerator commented 11 months ago

Operating system

macOS

Joplin version

2.13.5

Desktop version info

Joplin 2.13.5 (prod, darwin)

Client ID: 64df9fdc01c6479ead3a1f7b132d48a6 Sync Version: 3 Profile Version: 44 Keychain Supported: Yes

Revision: 1d04ec6

Current behaviour

Editing an HTML note with an attachment link in the rich text editor clears the link's target. For example,

<a href=":/93d25985c31c4aad91d5e710390de5f1" alt="syncReport-1689640089262.txt">syncReport-1689640089262.txt</a>

becomes

<p><a data-from-md="" href="#">syncReport-1689640089262.txt</a>. Some edit here.</p>

Reproduction steps

  1. Create a new HTML note (for example, by exporting a note as HTML, then importing it as HTML)
  2. Open the note in the markdown/HTML editor (HTML in this case)
  3. Delete the note's content
  4. Attach a file to the note using the "attach" button
  5. Switch to the rich text editor
  6. Edit the note
  7. Switch back to the markdown/HTML editor

Expected behaviour

The resource link should be preserved.

Logs

Note: This log is from the Electron development tools and starts just before attaching a resource to the HTML note.

Logger.ts:254 07:58:35: Preparing scheduled sync
Logger.ts:254 07:58:35: Starting scheduled sync
Logger.ts:254 07:58:35: Synchronizer: Sync: starting: Starting synchronisation to target 3... supportsAccurateTimestamp = false; supportsMultiPut = false [1699977515154]
Logger.ts:254 07:58:35: Synchronizer: Indexing resources...
Logger.ts:254 07:58:35: ResourceService::indexNoteResources: Start
Logger.ts:254 07:58:35: ResourceService::indexNoteResources: Completed
Logger.ts:254 07:58:35: Synchronizer: Sync target remote info: SyncInfo {version_: 3, masterKeys_: Array(5), e2ee_: {…}, activeMasterKeyId_: {…}, ppk_: {…}}
Logger.ts:254 07:58:35: Synchronizer: Sync target is already setup - checking it...
Logger.ts:254 07:58:35: Synchronizer: Sync target local info: SyncInfo {version_: 3, masterKeys_: Array(5), e2ee_: {…}, activeMasterKeyId_: {…}, ppk_: {…}}
useMessageHandler.ts:18 Got ipc-message: noteRenderComplete undefined
Logger.ts:254 07:58:37: Synchronizer: Sync: updateRemote: local has changes: Note: (Local dd659c3451ff488eb6dd27fce922d4f9): (Remote dd659c3451ff488eb6dd27fce922d4f9.md)
Logger.ts:254 07:58:37: Synchronizer: Processing a path that has already been done: dd659c3451ff488eb6dd27fce922d4f9.md. sync_time was not updated? Remote item has an updated_time in the future?
Logger.ts:254 07:58:37: Synchronizer: Sync: finished: Synchronisation finished [1699977515154]
Logger.ts:254 07:58:37: Synchronizer: Operations completed: 
Logger.ts:254 07:58:37: Synchronizer: updateRemote: 1
Logger.ts:254 07:58:37: Synchronizer: Total folders: 25
Logger.ts:254 07:58:37: Synchronizer: Total notes: 717
Logger.ts:254 07:58:37: Synchronizer: Total resources: 982
Logger.ts:254 07:58:37: Sync has finished and note has never been changed - reloading it
Logger.ts:254 07:58:41: resourceHandling: Attaching /Users/MyUserName/Downloads/Link text.pdf
Logger.ts:254 07:58:41: resourceHandling: File was attached.
useMessageHandler.ts:18 Got ipc-message: noteRenderComplete undefined
TinyMCE.tsx:336 Loading script /Applications/Joplin.app/Contents/Resources/app.asar/vendor/lib/tinymce/tinymce.min.js
loadScript.ts:14 Loading script: {src: '/Applications/Joplin.app/Contents/Resources/app.asar/vendor/lib/tinymce/tinymce.min.js', id: 'tinyMceScript', loaded: false}
TinyMCE.tsx:336 Loading script gui/NoteEditor/NoteBody/TinyMCE/plugins/lists.js
loadScript.ts:14 Loading script: {src: 'gui/NoteEditor/NoteBody/TinyMCE/plugins/lists.js', id: 'tinyMceListsPluginScript', loaded: false}
useMessageHandler.ts:18 Got ipc-message: noteRenderComplete null
useMessageHandler.ts:18 Got ipc-message: noteRenderComplete null
Logger.ts:254 07:58:46: SearchEngine: Updating FTS table...
Logger.ts:254 07:58:47: SearchEngine: Updated FTS table in 21ms. Inserted: 1. Deleted: 0
useMessageHandler.ts:18 Got ipc-message: noteRenderComplete null
useMessageHandler.ts:18 Got ipc-message: noteRenderComplete null
2useMessageHandler.ts:18 Got ipc-message: noteRenderComplete undefined

Additional information

This has also been tested on Linux (Ubuntu 23.10) with Joplin 2.12.19. The issue is present in that version as well.

personalizedrefrigerator commented 10 months ago

This also happens with markdown notes, provided that resource links are written with HTML.

personalizedrefrigerator commented 10 months ago

It seems to be related to HTML sanitization:

https://github.com/laurent22/joplin/blob/cadc9749990213a94bf0aaeb98e22095cb4ac78d/packages/renderer/htmlUtils.ts#L270-L272

In this case, allowedFilePrefixes is empty and the URL is replaced with #.