Make WordPress Core

Ticket #11360: 11360.2.diff

File 11360.2.diff, 2.9 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 b9383f5..3f742a0 100644
    function wp_rel_nofollow( $text ) { 
    23322332function wp_rel_nofollow_callback( $matches ) {
    23332333        $text = $matches[1];
    23342334        $atts = shortcode_parse_atts( $matches[1] );
    2335         $rel = 'nofollow';
     2335        $rel  = 'nofollow';
     2336
     2337        if ( preg_match( '%href=["\'](' . set_url_scheme( home_url(), 'http' ) . ')?(\.){0,2}(/|#|["\'])%i', $text ) ||
     2338             preg_match( '%href=["\'](' . set_url_scheme( home_url(), 'https' ) . ')?(\.){0,2}(/|#|["\'])%i', $text )) {
     2339                return "<a $text>";
     2340        }
     2341
    23362342        if ( ! empty( $atts['rel'] ) ) {
    23372343                $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
    23382344                if ( false === array_search( 'nofollow', $parts ) ) {
  • new file tests/phpunit/tests/formatting/relNofollow.php

    diff --git tests/phpunit/tests/formatting/relNofollow.php tests/phpunit/tests/formatting/relNofollow.php
    new file mode 100644
    index 0000000..dca2886
    - +  
     1<?php
     2
     3/**
     4 * @group formatting
     5 */
     6class Tests_Rel_Nofollow extends WP_UnitTestCase {
     7        /**
     8         * @ticket 11360
     9         * @dataProvider data_wp_rel_nofollow
     10         */
     11        public function test_wp_rel_nofollow( $input, $output ) {
     12                return $this->assertEquals( wp_slash( $output ), wp_rel_nofollow( $input ) );
     13        }
     14
     15        public function data_wp_rel_nofollow() {
     16                $home_url_http  = set_url_scheme( home_url(), 'http' );
     17                $home_url_https = set_url_scheme( home_url(), 'https' );
     18
     19                return array(
     20                        array(
     21                                '<a href="https://wordpress.org">Double Quotes</a>',
     22                                '<a href="https://wordpress.org" rel="nofollow">Double Quotes</a>',
     23                        ),
     24                        array(
     25                                "<a href='https://wordpress.org'>Single Quotes</a>",
     26                                "<a href='https://wordpress.org' rel=\"nofollow\">Single Quotes</a>",
     27                        ),
     28                        array(
     29                                '<a href="https://wordpress.org" title="Title">Multiple attributes</a>',
     30                                '<a href="https://wordpress.org" title="Title" rel="nofollow">Multiple attributes</a>',
     31                        ),
     32                        array(
     33                                '<a title="Title" href="https://wordpress.org">Multiple attributes</a>',
     34                                '<a title="Title" href="https://wordpress.org" rel="nofollow">Multiple attributes</a>',
     35                        ),
     36                        array(
     37                                '<a data-someflag href="https://wordpress.org">Multiple attributes</a>',
     38                                '<a data-someflag href="https://wordpress.org" rel="nofollow">Multiple attributes</a>',
     39                        ),
     40                        array(
     41                                '<a  data-someflag  title="Title"  href="https://wordpress.org" onclick=""  >Everything at once</a>',
     42                                '<a  data-someflag  title="Title"  href="https://wordpress.org" onclick=""   rel="nofollow">Everything at once</a>',
     43                        ),
     44                        array(
     45                                '<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
     46                                '<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
     47                        ),
     48                        array(
     49                                '<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
     50                                '<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
     51                        ),
     52                );
     53        }
     54}