fix: checks for zero value before retrieving objects#88
Merged
Conversation
|
Coverage report for commit: e94b948 Summary - Lines: 9.89% | Methods: 7.27%
🤖 comment via lucassabreu/comment-coverage-clover |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
Fixes an infinite-recursion edge case in CommentData::fromComment() caused by calling WordPress retrieval functions with a zero ID (notably get_comment(0) falling back to the global $comment), by guarding lookups with explicit non-zero checks.
Changes:
- Add
0 !== (int) ...guards before attemptingget_post()lookups for comment post IDs. - Add
0 !== (int) ...guards before attemptingget_comment()lookups for comment parent IDs. - Add
0 !== (int) ...guards before attemptingget_userdata()lookups for comment user IDs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return new static( | ||
| id: (int) $comment->comment_ID, | ||
| post: null !== get_post((int)$comment->comment_post_ID) ? PostData::fromPost(get_post((int)$comment->comment_post_ID)) : null, | ||
| post: 0 !== (int) $comment->comment_post_ID && null !== get_post((int)$comment->comment_post_ID) ? PostData::fromPost(get_post((int)$comment->comment_post_ID)) : null, |
| return new static( | ||
| id: (int) $comment->comment_ID, | ||
| post: null !== get_post((int)$comment->comment_post_ID) ? PostData::fromPost(get_post((int)$comment->comment_post_ID)) : null, | ||
| post: 0 !== (int) $comment->comment_post_ID && null !== get_post((int)$comment->comment_post_ID) ? PostData::fromPost(get_post((int)$comment->comment_post_ID)) : null, |
Comment on lines
+50
to
+51
| parent: 0 !== (int) $comment->comment_parent && null !== get_comment((int) $comment->comment_parent) ? CommentData::fromComment(get_comment((int) $comment->comment_parent)) : null, | ||
| user: 0 !== (int) $comment->user_id && false !== get_userdata((int) $comment->user_id) ? UserData::fromUser(get_userdata((int) $comment->user_id)) : null, |
Comment on lines
+50
to
+51
| parent: 0 !== (int) $comment->comment_parent && null !== get_comment((int) $comment->comment_parent) ? CommentData::fromComment(get_comment((int) $comment->comment_parent)) : null, | ||
| user: 0 !== (int) $comment->user_id && false !== get_userdata((int) $comment->user_id) ? UserData::fromUser(get_userdata((int) $comment->user_id)) : null, |
mvdhoek1
approved these changes
May 5, 2026
Rovasch
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the comment being retrieved is equal to the global $comment, the parent lookup for a comment without parent causes an infinite loop.