fix infinite cycle when template is descendant of an instance

This commit is contained in:
zadam 2021-02-09 20:15:14 +01:00
parent 96a5cb23f3
commit 0040334e89

View File

@ -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;