Taxonomy::getSiblingIds() leads to endless loop

Created on 6 October 2023, about 1 year ago
Updated 13 October 2023, about 1 year ago

Problem/Motivation

In some search Taxonomy::getSiblingIds() results in endless loop

Steps to reproduce

Difficult to say how to reproduce it as it relates to specific search results. It happens when $topLevelTerms is empty in the the first call of getSiblingIds() so it triggers second invoke: $this->getSiblingIds($ids, $parentIds). By the definition of function getSiblingIds(), this second call loops the original $ids again while using $parentIds as "$activeIds" which does not feel right. In addition to that, the condition check: if (!$activeIds || in_array($id, $activeIds)) would never be true in this case since $parentIds is not empty while $id is not in $activeIds($parentIds).

    return array_diff(
      array_merge(
        $childIds,
        $topLevelTerms,
        (!$topLevelTerms && $parentSiblings) ? $this->getSiblingIds($ids, $parentIds) : []
      ),
      $ids
    );

Proposed resolution

Feels to me the intention of (!$topLevelTerms && $parentSiblings) ? $this->getSiblingIds($ids, $parentIds) : [] is trying to fetch top level terms so it should be fixed as (!$topLevelTerms && $parentSiblings) ? $this->getSiblingIds($parentIds) : []

🐛 Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024