Make WordPress Core

Changeset 45990


Ignore:
Timestamp:
09/04/2019 05:36:46 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Improve handling the existing rel attribute in wp_rel_nofollow_callback().

Props xknown, sstoqnov.

Location:
trunk
Files:
2 edited

Legend:

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

    r45932 r45990  
    30443044function wp_rel_nofollow_callback( $matches ) {
    30453045    $text = $matches[1];
    3046     $atts = shortcode_parse_atts( $matches[1] );
     3046    $atts = wp_kses_hair( $matches[1], wp_allowed_protocols() );
    30473047    $rel  = 'nofollow';
    30483048
    30493049    if ( ! empty( $atts['href'] ) ) {
    3050         if ( in_array( strtolower( wp_parse_url( $atts['href'], PHP_URL_SCHEME ) ), array( 'http', 'https' ), true ) ) {
    3051             if ( strtolower( wp_parse_url( $atts['href'], PHP_URL_HOST ) ) === strtolower( wp_parse_url( home_url(), PHP_URL_HOST ) ) ) {
     3050        if ( in_array( strtolower( wp_parse_url( $atts['href']['value'], PHP_URL_SCHEME ) ), array( 'http', 'https' ), true ) ) {
     3051            if ( strtolower( wp_parse_url( $atts['href']['value'], PHP_URL_HOST ) ) === strtolower( wp_parse_url( home_url(), PHP_URL_HOST ) ) ) {
    30523052                return "<a $text>";
    30533053            }
     
    30563056
    30573057    if ( ! empty( $atts['rel'] ) ) {
    3058         $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) );
     3058        $parts = array_map( 'trim', explode( ' ', $atts['rel']['value'] ) );
    30593059        if ( false === array_search( 'nofollow', $parts ) ) {
    30603060            $parts[] = 'nofollow';
     
    30653065        $html = '';
    30663066        foreach ( $atts as $name => $value ) {
    3067             $html .= "{$name}=\"" . esc_attr( $value ) . '" ';
     3067            if ( isset( $value['vless'] ) && 'y' === $value['vless'] ) {
     3068                $html .= $name . ' ';
     3069            } else {
     3070                $html .= "{$name}=\"" . esc_attr( $value['value'] ) . '" ';
     3071            }
    30683072        }
    30693073        $text = trim( $html );
  • trunk/tests/phpunit/tests/formatting/WPRelNoFollow.php

    r42343 r45990  
    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.