Make WordPress Core

Opened 6 years ago

Closed 2 months ago

Last modified 3 weeks ago

#9959 closed defect (bug) (fixed)

wp_rel_nofollow_callback adds too many rel/nofollow attributes

Reported by: Denis-de-Bernardy Owned by: wonderboymusic
Milestone: 4.4 Priority: low
Severity: normal Version: 2.8
Component: Comments Keywords: has-patch needs-unit-tests
Focuses: Cc:


if you insert a link in a comment, like:

<a href="foo" rel="bar nofollow">

wp_rel_nofollow_callback() turns that into:

<a href="foo" rel="bar nofollow" rel="nofollow">

Here's a correct implementation of a strip_nofollow() function:


We'd probably want to do the same in WP, and then reverse it: add rel=nofollow if no rel is present, and add a nofollow to the rel if it's not in there already.

Attachments (4)

wp_rel_nofollow.txt (1.4 KB) - added by junsuijin 6 years ago.
formatting.php (81.5 KB) - added by junsuijin 6 years ago.
9959.patch (1.3 KB) - added by junsuijin 6 years ago.
9959.diff (1.8 KB) - added by wonderboymusic 2 months ago.

Download all attachments as: .zip

Change History (21)

#1 @junsuijin
6 years ago

  • Owner set to junsuijin
  • Status changed from new to reviewing

#2 @junsuijin
6 years ago

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

6 years ago

#3 @junsuijin
6 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

#4 @junsuijin
6 years ago

  • Status changed from reopened to accepted

#5 @junsuijin
6 years ago

  • Cc junsuijin@… added
  • Keywords has-patch added

6 years ago

#6 @Denis-de-Bernardy
6 years ago

  • Milestone changed from Future Release to 2.9

#7 @junsuijin
6 years ago

  • Keywords needs-patch removed

#8 @Denis-de-Bernardy
6 years ago

Some test data to play with

$text = '
<a href="foo" rel="tag nofollow ext">
<a href="foo" rel="nofollow ext">
<a href="foo" rel="tag ext">
<a href="foo" rel ="tag">
<a href="foo" rel="">
<a href="foo" rel
<a href="foo" rel= "">
<a href="foo">
a href="foo">

#10 follow-up: @Denis-de-Bernardy
6 years ago

per IRC discussion, there also is a separate issue. unless I'm mistaking, it's possible to add a link in a comment without nofollow, as such:


#11 @aaroncampbell
6 years ago

  • Cc aaroncampbell added

#12 @ryan
6 years ago

  • Milestone changed from 2.9 to Future Release

#13 in reply to: ↑ 10 @dilbert4life
5 years ago

  • Cc dilbert4life added

Replying to Denis-de-Bernardy:

To prevent that, we could have it remove line breaks from the comment text, and then run the wp_rel_nofollow function. However, the original problem is still present in 3.1.1. I'll look into this using 9959.patch as a starting point.

#14 @chriscct7
14 months ago

  • Severity changed from minor to normal

2 months ago

#15 @wonderboymusic
2 months ago

  • Keywords needs-unit-tests added
  • Milestone changed from Future Release to 4.4
  • Owner changed from junsuijin to wonderboymusic
  • Status changed from accepted to assigned

#16 @wonderboymusic
2 months ago

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

In 34277:

Comments: in wp_rel_nofollow_callback(), account for the fact that a link might already have a rel attribute. Currently, if a link already has a rel, it will result it duplicate attributes on the element with conflicting values.

Adds unit tests.

Props junsuijin, wonderboymusic.
Fixes #9959.

#17 @SergeyBiryukov
3 weeks ago

In 35505:

Add missing @group to Tests_Rel_No_Follow.

See #9959.

Note: See TracTickets for help on using tickets.