Make WordPress Core

Changeset 36125


Ignore:
Timestamp:
12/30/2015 11:19:11 PM (9 years ago)
Author:
swissspidy
Message:

Comments: Don't nofollow links within the site.

Fixes #11360.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r36100 r36125  
    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'] ) );
  • trunk/tests/phpunit/tests/formatting/WPRelNoFollow.php

    r35505 r36125  
    2323        $this->assertEquals( $expected, wp_rel_nofollow( $content ) );
    2424    }
     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    }
    2577}
Note: See TracChangeset for help on using the changeset viewer.