mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-08-29 02:04:30 +08:00
fix: prevent cyclic tree state in moveFolder by blocking self/descendant moves
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user