Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#46291 closed defect (bug) (fixed)

Twenty Nineteen: Avoid nested links in comment meta section of the comment in TwentyNineteen_Walker_Comment class

Reported by: iamdmitrymayorov's profile iamdmitrymayorov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.2 Priority: normal
Severity: normal Version:
Component: Bundled Theme Keywords: has-patch dev-feedback
Focuses: Cc:


If a user adds his URL when leaving a comment, his avatar and name becomes a link to the URL he provided. It appears though that there is a bug in TwentyNineteen_Walker_Comment class that produces a markup with nested links in this case. This is how the output markup looks like:

<div class="comment-author vcard">
  <a href="" rel="external nofollow" class="url"><img alt='' src='...' srcset='... 2x' class='avatar avatar-60 photo' height='60' width='60' />
    <b class="fn"><a href='' rel='external nofollow' class='url'>A WordPress Commenter</a></b>
    <span class="screen-reader-text says">says:</span>
</div><!-- .comment-author -->

And if you inspect the code in Chrome, it gets even funkier. Chrome automatically closes the first link tag and adds an empty <b class="fn"></b> inside:

I understand original idea: put an image and an author name inside one link tag, which is a valid HTML5 markup.

However it doesn't work because get_comment_author_link() is used to output the comment author name. This function falls back to get_comment_author() if there is no URL, but in our case it breaks the markup when the URL is present.

We can easily fix it by using get_comment_author() instead. The comment author name will still be clickable and focusable because it will be inside the link tag.

Attachments (3)

46291.diff (715 bytes) - added by iamdmitrymayorov 5 years ago.
46291.2.diff (678 bytes) - added by mukesh27 5 years ago.
Updated Patch.
46291.3.diff (1.4 KB) - added by iamdmitrymayorov 5 years ago.
Updated patch.

Download all attachments as: .zip

Change History (10)

#1 @iamdmitrymayorov
5 years ago

  • Keywords has-patch added

#2 @mukesh27
5 years ago

  • Keywords dev-feedback added

Hi @iamdmitrymayorov, Welcome to WordPress Trac! Thank you for your ticket.

Good cache.

Updated patch as theme already define variable for that function $comment_author = get_comment_author( $comment ); so just needs to use that variable instead of add another call of get_comment_author( $comment ) function.

5 years ago

Updated Patch.

5 years ago

Updated patch.

#3 @iamdmitrymayorov
5 years ago

Thanks for the update @mukesh27. This actually brings me to another minor observation. $comment_author_link becomes useless if this gets merged. In fact, it was unused before, but I think it was just an oversight, because the link was actually outputted inside the <b> tag. Anyway, there is probably no point in keeping that variable there.

This ticket was mentioned in Slack in #core-themes by dmtrmrv. View the logs.

5 years ago

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

5 years ago

#6 @SergeyBiryukov
5 years ago

  • Milestone changed from Awaiting Review to 5.2
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#7 @SergeyBiryukov
5 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 44771:

Twenty Nineteen: Avoid nested comment author links in TwentyNineteen_Walker_Comment::html5_comment().

Props iamdmitrymayorov, mukesh27.
Fixes #46291.

Note: See TracTickets for help on using tickets.