1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

All: Fixes #3334: Prevent notebook to be the parent of itself

This commit is contained in:
Laurent Cozic 2020-06-07 12:47:43 +01:00
parent 5be8c2cdcf
commit f36e0c2513
2 changed files with 15 additions and 1 deletions

View File

@ -185,7 +185,6 @@ describe('models_Folder', function() {
}));
it('should recursively find folder path', asyncTest(async () => {
const f1 = await Folder.save({ title: 'folder1' });
const f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
const f3 = await Folder.save({ title: 'folder3', parent_id: f2.id });
@ -218,4 +217,10 @@ describe('models_Folder', function() {
expect(sortedFolderTree[1].children[0].id).toBe(f5.id);
expect(sortedFolderTree[2].id).toBe(f6.id);
}));
it('should not allow setting a notebook parent as itself', asyncTest(async () => {
const f1 = await Folder.save({ title: 'folder1' });
const hasThrown = await checkThrowAsync(() => Folder.save({ id: f1.id, parent_id: f1.id }, { userSideValidation: true }));
expect(hasThrown).toBe(true);
}));
});

View File

@ -125,6 +125,11 @@ class Folder extends BaseItem {
const folder = foldersById[parentId];
if (!folder) break; // https://github.com/laurent22/joplin/issues/2079
folder.note_count = (folder.note_count || 0) + noteCount.note_count;
// Should not happen anymore but just to be safe, add the check below
// https://github.com/laurent22/joplin/issues/3334
if (folder.id === folder.parent_id) break;
parentId = folder.parent_id;
} while (parentId);
});
@ -403,6 +408,10 @@ class Folder extends BaseItem {
if (!('duplicateCheck' in options)) options.duplicateCheck = true;
if (!('reservedTitleCheck' in options)) options.reservedTitleCheck = true;
if (!('stripLeftSlashes' in options)) options.stripLeftSlashes = true;
if (o.id && o.parent_id && o.id === o.parent_id) {
throw new Error('Parent ID cannot be the same as ID');
}
}
if (options.stripLeftSlashes === true && o.title) {