Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_term_tree(): fix infinite loop for non-existent parent #2687

Merged
merged 2 commits into from
Mar 28, 2022
Merged

get_term_tree(): fix infinite loop for non-existent parent #2687

merged 2 commits into from
Mar 28, 2022

Conversation

rebeccahum
Copy link
Contributor

Description of the Change

When calling get_term_tree() and a term has a parent ID that doesn't exist (possibly due to reasons such as a bad import), we should check for that to prevent an infinite loop from occurring.

Reproduction steps:

$terms = array(
	0 => (object)  array
	(
		'term_id' => 2,
		'name' => 'ingredients',
		'slug' => 'ingredients',
		'term_group' => 0,
		'term_taxonomy_id' => 2,
		'taxonomy' => 'category',
		'description' => '',
		'parent' => 0,
		'count' => 1,
		'filter' => 'raw'
	),

);

$terms[0]->parent = 100; // non-existing parent in the terms

print_r( \ElasticPress\Utils\get_term_tree( $terms ) );

Alternate Designs

N/A

Possible Drawbacks

None that comes to mind.

Verification Process

Reproduce the reproduction steps with the PR applied and ensure no critical errors occur.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Fixed - get_term_tree() will no longer infinite loop when parent ID is non-existent

Credits

Props @rebeccahum

@felipeelia felipeelia linked an issue Mar 28, 2022 that may be closed by this pull request
@felipeelia felipeelia added this to the 4.1.0 milestone Mar 28, 2022
@felipeelia felipeelia merged commit 46c8dfb into 10up:develop Mar 28, 2022
@rebeccahum rebeccahum deleted the fix/get_term_tree_nonexistent_parent branch July 8, 2022 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: get_term_tree() can lead to an infinite loop
2 participants