Make WordPress Core

Ticket #33591: 33591.6-refresh.patch

File 33591.6-refresh.patch, 4.5 KB (added by rebasaurus, 5 years ago)

Refresh

  • src/wp-includes/feed.php

    diff --git a/src/wp-includes/feed.php b/src/wp-includes/feed.php
    index d2fd25ecb0..8fc9874da6 100644
    a b function atom_enclosure() { 
    519519                if ( 'enclosure' === $key ) {
    520520                        foreach ( (array) $val as $enc ) {
    521521                                $enclosure = explode( "\n", $enc );
     522
     523                                $url = $type = '';
     524                                $length = 0;
     525
     526                                $mimes = get_allowed_mime_types();
     527
     528                                // Parse url
     529                                if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) {
     530                                        $url = trim( $enclosure[0] );
     531                                }
     532
     533                                // Parse length and type
     534                                foreach( range( 1, 2 ) as $i ) {
     535                                        if ( isset( $enclosure[$i] ) ) {
     536                                                if( is_numeric( $enclosure[$i] ) ) {
     537                                                        $length = trim( $enclosure[$i] );
     538                                                } elseif ( in_array( $enclosure[$i], $mimes ) ) {
     539                                                        $type = trim( $enclosure[$i] );
     540                                                }
     541                                        }
     542                                }
     543
     544                                $html_link_tag = sprintf(
     545                                        "<link href=\"%s\" rel=\"enclosure\" length=\"%d\" type=\"%s\" />\n",
     546                                        esc_url ( $url ),
     547                                        esc_attr( $length ),
     548                                        esc_attr( $type )
     549                                );
    522550                                /**
    523551                                 * Filters the atom enclosure HTML link tag for the current post.
    524552                                 *
    function atom_enclosure() { 
    526554                                 *
    527555                                 * @param string $html_link_tag The HTML link tag with a URI and other attributes.
    528556                                 */
    529                                 echo apply_filters( 'atom_enclosure', '<link href="' . esc_url( trim( $enclosure[0] ) ) . '" rel="enclosure" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( trim( $enclosure[2] ) ) . '" />' . "\n" );
     557                                echo apply_filters( 'atom_enclosure', $html_link_tag );
    530558                        }
    531559                }
    532560        }
  • tests/phpunit/tests/feed/atom.php

    diff --git a/tests/phpunit/tests/feed/atom.php b/tests/phpunit/tests/feed/atom.php
    index 56f15e5d0d..7ca0bbc969 100644
    a b class Tests_Feeds_Atom extends WP_UnitTestCase { 
    205205                        }
    206206                }
    207207        }
     208
     209        /**
     210         * @test 33591
     211         */
     212        function test_atom_enclosure_with_extended_url_length_type_parsing()
     213        {
     214                $enclosures = array(
     215                        array(
     216                                'actual'        => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4",     // url length type
     217                                'expected'      => array(
     218                                        'href'          => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4",
     219                                        'length'        => 318465,
     220                                        'type'          => "video/mp4"
     221                                )
     222                        ),
     223                        array(
     224                                        'actual'        => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\nvideo/mp4\n318465",     // url type length
     225                                        'expected'      => array(
     226                                                'href'          => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4",
     227                                                'length'        => 318465,
     228                                                'type'          => "video/mp4"
     229                                        )
     230                        ),
     231                        array(
     232                                        'actual'        => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465",                // url length
     233                                        'expected'      => array(
     234                                                'href'          => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4",
     235                                                'length'        => 318465,
     236                                                'type'          => ""
     237                                        )
     238                        ),
     239                        array(
     240                                        'actual'        => "https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3\n\naudio/mpeg",          // url type
     241                                        'expected'      => array(
     242                                                'href'          => "https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3",
     243                                                'length'        => 0,
     244                                                'type'          => "audio/mpeg"
     245                                        )
     246                        ),
     247                        array(
     248                                        'actual'        => "https://wordpress.dev/wp-content/uploads/2016/01/test.mp4",                         // url
     249                                        'expected'      => array(
     250                                                'href'          => "https://wordpress.dev/wp-content/uploads/2016/01/test.mp4",
     251                                                'length'        => 0,
     252                                                'type'          => ""
     253                                        )
     254                        ),
     255                );
     256
     257                $post_id = end( self::$posts );
     258                foreach( $enclosures as $enclosure ) {
     259                        add_post_meta( $post_id, 'enclosure', $enclosure['actual'] );
     260                }
     261                $this->go_to( '/?feed=atom' );
     262                $feed = $this->do_atom();
     263                $xml = xml_to_array( $feed );
     264                $entries = xml_find( $xml, 'feed', 'entry' );
     265                $entries = array_slice( $entries, 0, 1 );
     266
     267                foreach ( $entries as $key => $entry ) {
     268                        $links = xml_find( $entries[$key]['child'], 'link' );
     269                        $i = 0;
     270                        foreach ( (array) $links as $link ) {
     271                                if ( 'enclosure' == $link['attributes']['rel'] ) {
     272                                        $this->assertEquals( $enclosures[$i]['expected']['href'] , $link['attributes']['href'] );
     273                                        $this->assertEquals( $enclosures[$i]['expected']['length'] , $link['attributes']['length'] );
     274                                        $this->assertEquals( $enclosures[$i]['expected']['type'] , $link['attributes']['type'] );
     275                                        $i++;
     276                                }
     277                        }
     278                }
     279        }
    208280}