WordPress.org

Make WordPress Core

Ticket #45352: 45352.3.diff

File 45352.3.diff, 1.5 KB (added by peterwilsoncc, 23 months ago)
  • src/wp-includes/formatting.php

    diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
    index 462ebaf1f4..2c9c9f820a 100644
    a b function wp_targeted_link_rel_callback( $matches ) { 
    30653065         */
    30663066        $rel = apply_filters( 'wp_targeted_link_rel', 'noopener noreferrer', $link_html );
    30673067
     3068        // Avoid additional regex if rel tag removed for targeted links.
     3069        if ( empty( $rel ) ) {
     3070                return "<a $link_html>";
     3071        }
     3072
    30683073        // Value with delimiters, spaces around are optional.
    30693074        $attr_regex = '|rel\s*=\s*?(\\\\{0,1}["\'])(.*?)\\1|i';
    30703075        preg_match( $attr_regex, $link_html, $rel_match );
  • tests/phpunit/tests/formatting/WPTargetedLinkRel.php

    diff --git a/tests/phpunit/tests/formatting/WPTargetedLinkRel.php b/tests/phpunit/tests/formatting/WPTargetedLinkRel.php
    index 49c843ec2c..695ca625f0 100644
    a b class Tests_Targeted_Link_Rel extends WP_UnitTestCase { 
    7171                $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">Change me</a> <a href="/">Do not change me</a></p>';
    7272                $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
    7373        }
     74
     75        public function test_ignore_if_wp_targeted_link_rel_nulled() {
     76                add_filter( 'wp_targeted_link_rel', '__return_empty_string' );
     77                $content  = '<p>Links: <a href="/" target="_blank">Do not change me</a></p>';
     78                $expected = '<p>Links: <a href="/" target="_blank">Do not change me</a></p>';
     79                $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
     80        }
    7481}