[wp-trac] [WordPress Trac] #48261: "noopener noreferrer" mis-parses links with "rel=" parameters

WordPress Trac noreply at wordpress.org
Wed Oct 9 21:41:21 UTC 2019


#48261: "noopener noreferrer" mis-parses links with "rel=" parameters
--------------------------------------+------------------------------
 Reporter:  mvandemar                 |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Formatting                |     Version:  5.2.3
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------
Changes (by birgire):

 * keywords:  needs-patch needs-unit-tests => has-patch has-unit-tests


Old description:

> If a link contains a url parameter named "rel" and the rel="noopener
> noreferrer" attribute is triggered (ie. the link has the target="_blank"
> attribute as well) then it botches the parsing, and you wind up with a
> link that looks like:
>

> {{{
> <a href="https://www.somesite.com/index.php?v=yes&rel=0"
> noopener noreferrer" target="_blank">Anchor Text</a>
> }}}

New description:

 If a link contains a url parameter named "rel" and the rel="noopener
 noreferrer" attribute is triggered (ie. the link has the target="_blank"
 attribute as well) then it botches the parsing, and you wind up with a
 link that looks like:


 {{{
 <a href="https://www.somesite.com/index.php?v=yes&rel=0" noopener
 noreferrer" target="_blank">Anchor Text</a>
 }}}

--

Comment:

 Thanks @mvandemar for the report and screenshots.

 [attachment:"48261.diff"] is a first iteration, just to help the
 discussion further.

 This patch adds the extra condition {{{preg_match(
 '#(?:^\s*|\s+)rel\s*=#', $link_html )}}} is the attributes-regex are
 matched. Here {{{(?:)}}} is a non-capturing group and we check if rel is
 the first attribute (that can be without white space from left) or the
 second (or later) attribute (that need a white space from left). I first
 tried to modify the existing attributes-regex with this approach but it
 ended up with more changes, so I currently prefer this approach.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48261#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list