Make WordPress Core

Opened 7 years ago

Last modified 4 months ago

#40143 new defect (bug)

Comment template functions don't check for comment existence

Reported by: sergeybiryukov's profile 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 (2)

40143.patch (30.2 KB) - added by SergeyBiryukov 7 years ago.
40143.diff (24.3 KB) - added by david.binda 4 months ago.

Download all attachments as: .zip

Change History (10)

#1 @SergeyBiryukov
7 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.

7 years ago

#3 @flixos90
7 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.

This ticket was mentioned in PR #3984 on WordPress/wordpress-develop by thomasplevy.

16 months ago

  • Keywords has-unit-tests added; needs-unit-tests removed

Updates get_comment_text() to ensure the supplied comment exists & add related tests.

Trac ticket:

#7 @thomasplevy
16 months ago

  • Keywords needs-unit-tests added; has-unit-tests removed

Hey @SergeyBiryukov thanks for the alert on the related issue. I've wrote up what I think is a passable fix for the issue you raised here.

#8 @david.binda
4 months ago

The undefined property notices became warnings in PHP8.

I have updated the patch, which no longer cleanly applies to trunk.

4 months ago

Note: See TracTickets for help on using tickets.