yii2 icon indicating copy to clipboard operation
yii2 copied to clipboard

`detectLoop()` not include detection at the child level.

Open WangPinChen opened this issue 6 months ago • 3 comments

in yii\rbac\DbManager.php Image

The loop starts checking from the grandchild level, but the child level is not being checked. Therefore, when I use canAddChild(), it cannot effectively validate the case where a parent is being added to its own child.

WangPinChen avatar Jun 06 '25 06:06 WangPinChen

Any idea for the fix?

samdark avatar Jun 09 '25 16:06 samdark

I think it should be:

protected function detectLoop($parent, $child)
{
    foreach ($this->getChildren($parent->name) as $directChild) {
        if ($directChild->name === $child->name) {
            return true;
        }

        if ($this->detectLoop($directChild, $child)) {
            return true;
        }
    }

    return false;
}

WangPinChen avatar Jun 10 '25 06:06 WangPinChen

Do you have time to do a pull request?

samdark avatar Jun 10 '25 12:06 samdark