WordPress.org

Make WordPress Core

Ticket #46886: 46886-2.diff

File 46886-2.diff, 1.3 KB (added by birgire, 7 months ago)
  • src/wp-includes/formatting.php

    diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
    index dc97605..3d0d0f7 100644
    function wp_rel_nofollow_callback( $matches ) { 
    30393039 */
    30403040function wp_targeted_link_rel( $text ) {
    30413041        // Don't run (more expensive) regex if no links with targets.
    3042         if ( stripos( $text, 'target' ) !== false && stripos( $text, '<a ' ) !== false ) {
     3042        if ( stripos( $text, ' target' ) !== false && stripos( $text, '<a ' ) !== false ) {
    30433043                $text = preg_replace_callback( '|<a\s([^>]*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $text );
    30443044        }
    30453045
  • tests/phpunit/tests/formatting/WPTargetedLinkRel.php

    diff --git tests/phpunit/tests/formatting/WPTargetedLinkRel.php tests/phpunit/tests/formatting/WPTargetedLinkRel.php
    index 08f8ac1..4655d2c 100644
    class Tests_Targeted_Link_Rel extends WP_UnitTestCase { 
    101101
    102102                $this->assertEquals( $expected, $post->post_content );
    103103        }
     104
     105        /**
     106         * Ensure the data-target attribute is ignored.
     107         *
     108         * @ticket 46886.
     109         */
     110        public function test_ignore_data_target_attribute() {
     111                $content  = '<a href="https://example.com" data-target="thisandthat">click here</a>';
     112                $expected = $content;
     113                $this->assertSame( $expected, wp_targeted_link_rel( $content ) );
     114        }
     115
    104116}