Make WordPress Core

Opened 10 months ago

Closed 10 months ago

Last modified 10 months ago

#61715 closed defect (bug) (fixed)

Only type cast a scalar $comment_id in get_comment_author_link()

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.7 Priority: normal
Severity: normal Version: 6.2
Component: Comments Keywords: good-first-bug has-patch
Focuses: Cc:

Description

Background: #60475, #61681.

In [58755], get_comment_author() was updated to only cast $comment_id to a string if the value is scalar.

As noted by @mukesh27, get_comment_author_link() has a similar code fragment (introduced in [55289]) and should be updated too for consistency.

Attachments (2)

get_comment_author.patch (102.6 KB) - added by iflairwebtechnologies 10 months ago.
Improve type handling and readability in get_comment_author() function
61715.patch (2.7 KB) - added by iflairwebtechnologies 10 months ago.
Fix for comment template issue in wp-includes #61715. Please review new patch file.

Download all attachments as: .zip

Change History (11)

This ticket was mentioned in PR #7066 on WordPress/wordpress-develop by @narenin.


10 months ago
#1

  • Keywords has-patch added; needs-patch removed

#2 @mukesh27
10 months ago

Thanks, @narenin, for the PR.

Just for your information, the good-first-bug type is intended for new contributors to help them onboard. Since you are already familiar with contributing, please avoid submitting PRs or patches for these types of tickets.

Hope you understand. Thanks!

#3 @narenin
10 months ago

Thanks for reviewing the PR @mukesh27

I will take care of this.

@iflairwebtechnologies
10 months ago

Improve type handling and readability in get_comment_author() function

#4 follow-up: @iflairwebtechnologies
10 months ago

Reviewed and updated the get_comment_author() function in wp-includes/comment-template.php to improve type handling and readability. This function is critical for retrieving and formatting the comment author's information in WordPress.

#5 in reply to: ↑ 4 @SergeyBiryukov
10 months ago

Replying to iflairwebtechnologies:

Reviewed and updated the get_comment_author() function in wp-includes/comment-template.php to improve type handling and readability.

Thanks for the patch! I might be missing something, but I don't see any changes to the get_comment_author_link() function in that patch, which was the point of this ticket. Instead, the patch appears to remove all of the contents in the wp-includes/comment-template.php file.

@iflairwebtechnologies
10 months ago

Fix for comment template issue in wp-includes #61715. Please review new patch file.

@mukesh27 commented on PR #7084:


10 months ago
#7

Thanks for the PR.

It's duplicate PR of #7066

#8 @SergeyBiryukov
10 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 58809:

Comments: Only type cast a scalar $comment_id in get_comment_author_link().

This aims to resolve a fatal error when the incoming $comment_id is an instance of WP_Comment (or any object) without a comment_ID property defined, or if it's empty:

Object of class WP_Comment could not be converted to string

This commit mirrors the changes previously made for a similar code fragment in get_comment_author().

Includes:

  • Unit tests to demonstrate the fatal error and validate the fix.
  • Changing the default value for a non-existent comment ID in get_comment_author() from an empty string to zero as a numeric string, for consistency with get_comment_ID().

Follow-up to [52818], [55289], [58335], [58755].

Props narenin, mukesh27, iflairwebtechnologies, umeshsinghin, SergeyBiryukov.
Fixes #61715.

@SergeyBiryukov commented on PR #7066:


10 months ago
#9

Thanks for the PR! Merged in r58809.

Note: See TracTickets for help on using tickets.