Make WordPress Core

Opened 2 years ago

Last modified 2 months ago

#41846 new defect (bug)

Avoid PHP notice in get_comment_reply_link() for null comment

Reported by: birgire Owned by:
Milestone: 5.3 Priority: normal
Severity: normal Version: 2.7
Component: Comments Keywords: has-patch has-unit-tests
Focuses: Cc:


When I was working on tests for get_comment_reply_link() I got a PHP notice:

Notice	Trying to get property of non-object ...

with inputs like:

get_comment_reply_link( array( 'depth' => 1, 'max_depth' => 2 ) );

when there's no current global comment available and the input comment is null.

That's because of this part:

$comment = get_comment( $comment );

if ( empty( $post ) ) {
    $post = $comment->comment_post_ID;

where there's no validation for $comment.

Attachments (2)

41846.patch (1.5 KB) - added by birgire 2 years ago.
41846.diff (1.4 KB) - added by earnjam 2 months ago.

Download all attachments as: .zip

Change History (5)

2 years ago

#1 @birgire
2 years ago

  • Keywords has-patch has-unit-tests added

In 41846.patch we added a comment validation, similar to the existing one for the post.

Included is a test.

Last edited 2 years ago by birgire (previous) (diff)

#2 @birgire
2 years ago

Related #38925

2 months ago

#3 @earnjam
2 months ago

  • Milestone changed from Awaiting Review to 5.3

Thanks @birgire! This looks good.

In 41846.diff I just made a few small whitespace CS fixes to the unit test and added the ticket number to the @ticket annotation in the docblock.

I'm going to go ahead and milestone this for the next release.

Note: See TracTickets for help on using tickets.