From 09e9ac4d006082b3dad1b7ea360091d634fba129 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 10 Mar 2021 22:54:55 +0100 Subject: [PATCH] prevent cycles in resolving the notepath, fixes #1730 --- package-lock.json | 2 +- src/public/app/entities/note_short.js | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index c7ec5ebc1..aebe0d41f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.46.2-beta", + "version": "0.46.3-beta", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index a97b74155..1cc4fd376 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -254,22 +254,39 @@ class NoteShort { return noteAttributeCache.attributes[this.noteId]; } - getAllNotePaths() { + getAllNotePaths(encounteredNoteIds = null) { if (this.noteId === 'root') { return [['root']]; } + if (!encounteredNoteIds) { + encounteredNoteIds = new Set(); + } + + encounteredNoteIds.add(this.noteId); + const parentNotes = this.getParentNotes(); let paths; if (parentNotes.length === 1) { // optimization for the most common case - paths = parentNotes[0].getAllNotePaths(); + if (encounteredNoteIds.has(parentNotes[0].noteId)) { + return []; + } + else { + paths = parentNotes[0].getAllNotePaths(encounteredNoteIds); + } } else { paths = []; for (const parentNote of parentNotes) { - paths.push(...parentNote.getAllNotePaths()); + if (encounteredNoteIds.has(parentNote.noteId)) { + continue; + } + + const newSet = new Set(encounteredNoteIds); + + paths.push(...parentNote.getAllNotePaths(newSet)); } }