Make WordPress Core

Ticket #11360: 11360.3.diff

File 11360.3.diff, 3.2 KB (added by swissspidy, 9 years ago)
  • src/wp-includes/formatting.php

    diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
    index ac28d34..0ad1b5d 100644
    function wp_rel_nofollow( $text ) { 
    23362336function wp_rel_nofollow_callback( $matches ) {
    23372337        $text = $matches[1];
    23382338        $atts = shortcode_parse_atts( $matches[1] );
    2339         $rel = 'nofollow';
     2339        $rel  = 'nofollow';
     2340
     2341        if ( preg_match( '%href=["\'](' . preg_quote( set_url_scheme( home_url(), 'http' ) ) . ')%i', $text ) ||
     2342             preg_match( '%href=["\'](' . preg_quote( set_url_scheme( home_url(), 'https' ) ) . ')%i', $text )
     2343        ) {
     2344                return "<a $text>";
     2345        }
     2346
    23402347        if ( ! empty( $atts['rel'] ) ) {
    23412348                $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
    23422349                if ( false === array_search( 'nofollow', $parts ) ) {
  • tests/phpunit/tests/formatting/WPRelNoFollow.php

    diff --git tests/phpunit/tests/formatting/WPRelNoFollow.php tests/phpunit/tests/formatting/WPRelNoFollow.php
    index 821bb93..bd13a83 100644
    class Tests_Rel_No_Follow extends WP_UnitTestCase { 
    2222                $expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow\">Code</a></p>';
    2323                $this->assertEquals( $expected, wp_rel_nofollow( $content ) );
    2424        }
    25 }
    26  No newline at end of file
     25
     26        /**
     27         * @ticket 11360
     28         * @dataProvider data_wp_rel_nofollow
     29         */
     30        public function test_wp_rel_nofollow( $input, $output ) {
     31                return $this->assertEquals( wp_slash( $output ), wp_rel_nofollow( $input ) );
     32        }
     33
     34        public function data_wp_rel_nofollow() {
     35                $home_url_http  = set_url_scheme( home_url(), 'http' );
     36                $home_url_https = set_url_scheme( home_url(), 'https' );
     37
     38                return array(
     39                        array(
     40                                '<a href="">Double Quotes</a>',
     41                                '<a href="" rel="nofollow">Double Quotes</a>',
     42                        ),
     43                        array(
     44                                '<a href="https://wordpress.org">Double Quotes</a>',
     45                                '<a href="https://wordpress.org" rel="nofollow">Double Quotes</a>',
     46                        ),
     47                        array(
     48                                "<a href='https://wordpress.org'>Single Quotes</a>",
     49                                "<a href='https://wordpress.org' rel=\"nofollow\">Single Quotes</a>",
     50                        ),
     51                        array(
     52                                '<a href="https://wordpress.org" title="Title">Multiple attributes</a>',
     53                                '<a href="https://wordpress.org" title="Title" rel="nofollow">Multiple attributes</a>',
     54                        ),
     55                        array(
     56                                '<a title="Title" href="https://wordpress.org">Multiple attributes</a>',
     57                                '<a title="Title" href="https://wordpress.org" rel="nofollow">Multiple attributes</a>',
     58                        ),
     59                        array(
     60                                '<a data-someflag href="https://wordpress.org">Multiple attributes</a>',
     61                                '<a data-someflag href="https://wordpress.org" rel="nofollow">Multiple attributes</a>',
     62                        ),
     63                        array(
     64                                '<a  data-someflag  title="Title"  href="https://wordpress.org" onclick=""  >Everything at once</a>',
     65                                '<a  data-someflag  title="Title"  href="https://wordpress.org" onclick=""   rel="nofollow">Everything at once</a>',
     66                        ),
     67                        array(
     68                                '<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
     69                                '<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
     70                        ),
     71                        array(
     72                                '<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
     73                                '<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
     74                        ),
     75                );
     76        }
     77}