WordPress.org

Make WordPress Core

Opened 23 months ago

Last modified 4 weeks 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:

Description

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 23 months ago.
41846.diff (1.4 KB) - added by earnjam 4 weeks ago.

Download all attachments as: .zip

Change History (5)

@birgire
23 months ago

#1 @birgire
23 months 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 23 months ago by birgire (previous) (diff)

@earnjam
4 weeks ago

#3 @earnjam
4 weeks 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.