Make WordPress Core

Opened 5 years ago

Last modified 4 months ago

#40143 new defect (bug)

Comment template functions don't check for comment existence

Reported by: SergeyBiryukov Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch needs-unit-tests
Focuses: Cc:


Discovered during debugging an issue with Circle Lite theme, which uses comment_text( true ) in kopa_comment_callback() function.

That, while being an invalid usage (the function treats true as a comment ID), causes an inconsistent behaviour, depending on the existence of the comment:

  • If the comment with ID 1 exists, the function returns its text, as expected. That's obviously not what the author of the theme intended, but still the correct behaviour of the function.
  • If the comment with ID 1 does not exist, the function returns the text of the current comment in the loop instead of an empty string. What happens is get_comment( $comment_ID ) returns null (as expected), but then null is passed to get_comment_text(), which treats it as the current comment.

After investigating more, it looks like most of comment template functions are either affected in a similar way or cause an undefined property notice when passed a non-existing comment ID. Let's bring some consistency here.

Attachments (1)

40143.patch (30.2 KB) - added by SergeyBiryukov 5 years ago.

Download all attachments as: .zip

Change History (6)

#1 @SergeyBiryukov
5 years ago

40143.patch fixes the inconsistencies and adds a couple of tests, but needs more tests.

All existing comment tests pass.

This ticket was mentioned in Slack in #core by flixos90. View the logs.

5 years ago

#3 @flixos90
5 years ago

  • Milestone changed from 4.8 to Future Release

Due to lack of feedback and discussion, punting this to future release. Feel free to put it back into the milestone if this is actually ready.

Note: See TracTickets for help on using tickets.