fix: prevent cyclic tree state in moveFolder by blocking self/descendant moves

This commit is contained in:
Anwarul Islam
2026-06-30 09:09:02 +06:00
parent e0591cf42e
commit 18f5a66768
@@ -533,6 +533,23 @@ const restCollectionDispatchers = defineDispatchers({
return {}
}
// Block self-move: moving a folder to its own location
if (path === destinationPath) {
console.error(
`Cannot move folder to itself. Skipping request to move folder '${path}'.`
)
return {}
}
// Block descendant move: moving a folder into itself or its descendants
// This would create a cyclic tree structure
if (destinationPath.startsWith(path + "/")) {
console.error(
`Cannot move folder into its descendant. Destination '${destinationPath}' is inside source '${path}'. Skipping request.`
)
return {}
}
const target = navigateToFolderWithIndexPath(
newState,
destinationIndexPaths
@@ -1201,6 +1218,23 @@ const gqlCollectionDispatchers = defineDispatchers({
return {}
}
// Block self-move: moving a folder to its own location
if (path === destinationPath) {
console.error(
`Cannot move folder to itself. Skipping request to move folder '${path}'.`
)
return {}
}
// Block descendant move: moving a folder into itself or its descendants
// This would create a cyclic tree structure
if (destinationPath.startsWith(path + "/")) {
console.error(
`Cannot move folder into its descendant. Destination '${destinationPath}' is inside source '${path}'. Skipping request.`
)
return {}
}
const target = navigateToFolderWithIndexPath(
newState,
destinationIndexPaths