diff --git a/src/wp-includes/feed.php b/src/wp-includes/feed.php index d56ce8b18e..0b84cc10a5 100644 --- a/src/wp-includes/feed.php +++ b/src/wp-includes/feed.php @@ -526,17 +526,17 @@ function atom_enclosure() { $mimes = get_allowed_mime_types(); - // Parse url + // Parse URL. if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) { $url = trim( $enclosure[0] ); } - // Parse length and type - foreach ( range( 1, 2 ) as $i ) { + // Parse length and type. + for ( $i = 1; $i <= 2; $i++ ) { if ( isset( $enclosure[ $i ] ) ) { if ( is_numeric( $enclosure[ $i ] ) ) { $length = trim( $enclosure[ $i ] ); - } elseif ( in_array( $enclosure[ $i ], $mimes ) ) { + } elseif ( in_array( $enclosure[ $i ], $mimes, true ) ) { $type = trim( $enclosure[ $i ] ); } } @@ -548,6 +548,7 @@ function atom_enclosure() { esc_attr( $length ), esc_attr( $type ) ); + /** * Filters the atom enclosure HTML link tag for the current post. * diff --git a/tests/phpunit/tests/feed/atom.php b/tests/phpunit/tests/feed/atom.php index 026f5eecc1..55a428e586 100644 --- a/tests/phpunit/tests/feed/atom.php +++ b/tests/phpunit/tests/feed/atom.php @@ -207,12 +207,13 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { } /** - * @test 33591 + * @ticket 33591 */ function test_atom_enclosure_with_extended_url_length_type_parsing() { $enclosures = array( array( - 'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", // url length type + // URL, length, type. + 'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", 'expected' => array( 'href' => 'https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4', 'length' => 318465, @@ -220,7 +221,8 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { ), ), array( - 'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\nvideo/mp4\n318465", // url type length + // URL, type, length. + 'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\nvideo/mp4\n318465", 'expected' => array( 'href' => 'https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4', 'length' => 318465, @@ -228,7 +230,8 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { ), ), array( - 'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465", // url length + // URL, length. + 'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465", 'expected' => array( 'href' => 'https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4', 'length' => 318465, @@ -236,7 +239,8 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { ), ), array( - 'actual' => "https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3\n\naudio/mpeg", // url type + // URL, type. + 'actual' => "https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3\n\naudio/mpeg", 'expected' => array( 'href' => 'https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3', 'length' => 0, @@ -244,7 +248,8 @@ class Tests_Feeds_Atom extends WP_UnitTestCase { ), ), array( - 'actual' => 'https://wordpress.dev/wp-content/uploads/2016/01/test.mp4', // url + // URL. + 'actual' => 'https://wordpress.dev/wp-content/uploads/2016/01/test.mp4', 'expected' => array( 'href' => 'https://wordpress.dev/wp-content/uploads/2016/01/test.mp4', 'length' => 0,