You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-26 22:41:17 +02:00
All: Fixes #3334: Prevent notebook to be the parent of itself
This commit is contained in:
@@ -185,7 +185,6 @@ describe('models_Folder', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('should recursively find folder path', asyncTest(async () => {
|
it('should recursively find folder path', asyncTest(async () => {
|
||||||
|
|
||||||
const f1 = await Folder.save({ title: 'folder1' });
|
const f1 = await Folder.save({ title: 'folder1' });
|
||||||
const f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
|
const f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
|
||||||
const f3 = await Folder.save({ title: 'folder3', parent_id: f2.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[1].children[0].id).toBe(f5.id);
|
||||||
expect(sortedFolderTree[2].id).toBe(f6.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);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -125,6 +125,11 @@ class Folder extends BaseItem {
|
|||||||
const folder = foldersById[parentId];
|
const folder = foldersById[parentId];
|
||||||
if (!folder) break; // https://github.com/laurent22/joplin/issues/2079
|
if (!folder) break; // https://github.com/laurent22/joplin/issues/2079
|
||||||
folder.note_count = (folder.note_count || 0) + noteCount.note_count;
|
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;
|
parentId = folder.parent_id;
|
||||||
} while (parentId);
|
} while (parentId);
|
||||||
});
|
});
|
||||||
@@ -403,6 +408,10 @@ class Folder extends BaseItem {
|
|||||||
if (!('duplicateCheck' in options)) options.duplicateCheck = true;
|
if (!('duplicateCheck' in options)) options.duplicateCheck = true;
|
||||||
if (!('reservedTitleCheck' in options)) options.reservedTitleCheck = true;
|
if (!('reservedTitleCheck' in options)) options.reservedTitleCheck = true;
|
||||||
if (!('stripLeftSlashes' in options)) options.stripLeftSlashes = 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) {
|
if (options.stripLeftSlashes === true && o.title) {
|
||||||
|
|||||||
Reference in New Issue
Block a user