Make WordPress Core

Changeset 45998 for branches/4.6


Ignore:
Timestamp:
09/04/2019 05:52:01 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Improve handling the existing rel attribute in wp_rel_nofollow_callback().

Merges [45990] to the 4.6 branch.
Props xknown, sstoqnov.

Location:
branches/4.6
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6

  • branches/4.6/src/wp-includes/formatting.php

    r44864 r45998  
    27142714function wp_rel_nofollow_callback( $matches ) {
    27152715        $text = $matches[1];
    2716         $atts = shortcode_parse_atts( $matches[1] );
     2716        $atts = wp_kses_hair( $matches[1], wp_allowed_protocols() );
    27172717        $rel  = 'nofollow';
    27182718
    27192719        if ( ! empty( $atts['href'] ) ) {
    2720                 $href_parts  = wp_parse_url( $atts['href'] );
     2720                $href_parts  = wp_parse_url( $atts['href']['value'] );
    27212721                $href_scheme = isset( $href_parts['scheme'] ) ? $href_parts['scheme'] : '';
    27222722                $href_host   = isset( $href_parts['host'] ) ? $href_parts['host'] : '';
     
    27312731
    27322732        if ( ! empty( $atts['rel'] ) ) {
    2733                 $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
     2733                $parts = array_map( 'trim', explode( ' ', $atts['rel']['value'] ) );
    27342734                if ( false === array_search( 'nofollow', $parts ) ) {
    27352735                        $parts[] = 'nofollow';
     
    27402740                $html = '';
    27412741                foreach ( $atts as $name => $value ) {
    2742                         $html .= "{$name}=\"" . esc_attr( $value ) . "\" ";
     2742                        if ( isset( $value['vless'] ) && 'y' === $value['vless'] ) {
     2743                                $html .= $name . ' ';
     2744                        } else {
     2745                                $html .= "{$name}=\"" . esc_attr( $value['value'] ) . '" ';
     2746                        }
    27432747                }
    27442748                $text = trim( $html );
  • branches/4.6/tests/phpunit/tests/formatting/WPRelNoFollow.php

    r36125 r45998  
    7575                );
    7676        }
     77
     78        public function test_append_no_follow_with_valueless_attribute() {
     79                $content = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>';
     80                $expected = '<p>This is some cool <a href=\"demo.com\" download rel=\"hola nofollow\">Code</a></p>';
     81                $this->assertEquals( $expected, wp_rel_nofollow( $content ) );
     82        }
    7783}
Note: See TracChangeset for help on using the changeset viewer.