Make WordPress Core

Changeset 46001


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

Improve handling the existing rel attribute in wp_rel_nofollow_callback().

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

Location:
branches/4.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

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

    r44841 r46001  
    23452345function wp_rel_nofollow_callback( $matches ) {
    23462346        $text = $matches[1];
    2347         $atts = shortcode_parse_atts( $matches[1] );
     2347        $atts = wp_kses_hair( $matches[1], wp_allowed_protocols() );
    23482348        $rel = 'nofollow';
    23492349        if ( ! empty( $atts['rel'] ) ) {
    2350                 $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
     2350                $parts = array_map( 'trim', explode( ' ', $atts['rel']['value'] ) );
    23512351                if ( false === array_search( 'nofollow', $parts ) ) {
    23522352                        $parts[] = 'nofollow';
    … …  
    23572357                $html = '';
    23582358                foreach ( $atts as $name => $value ) {
    2359                         $html .= "{$name}=\"" . esc_attr( $value ) . "\" ";
     2359                        if ( isset( $value['vless'] ) && 'y' === $value['vless'] ) {
     2360                                $html .= $name . ' ';
     2361                        } else {
     2362                                $html .= "{$name}=\"" . esc_attr( $value['value'] ) . '" ';
     2363                        }
    23602364                }
    23612365                $text = trim( $html );
  • branches/4.4/tests/phpunit/tests/formatting/WPRelNoFollow.php

    r35505 r46001  
    2323                $this->assertEquals( $expected, wp_rel_nofollow( $content ) );
    2424        }
     25
     26        public function test_append_no_follow_with_valueless_attribute() {
     27                $content = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>';
     28                $expected = '<p>This is some cool <a href=\"demo.com\" download rel=\"hola nofollow\">Code</a></p>';
     29                $this->assertEquals( $expected, wp_rel_nofollow( $content ) );
     30        }
    2531}
Note: See TracChangeset for help on using the changeset viewer.