From 0040334e89f95eab998327401a00ab950dffdd46 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 9 Feb 2021 20:15:14 +0100 Subject: [PATCH] fix infinite cycle when template is descendant of an instance --- src/public/app/entities/note_short.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index abccf5b87..45b69d8fd 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -493,11 +493,20 @@ class NoteShort { }); } - hasAncestor(ancestorNote) { + hasAncestor(ancestorNote, visitedNoteIds) { if (this.noteId === ancestorNote.noteId) { return true; } + if (!visitedNoteIds) { + visitedNoteIds = new Set(); + } else if (visitedNoteIds.has(this.noteId)) { + // to avoid infinite cycle when template is descendent of the instance + return false; + } + + visitedNoteIds.add(this.noteId); + for (const templateNote of this.getTemplateNotes()) { if (templateNote.hasAncestor(ancestorNote)) { return true;