Changeset 48429
- Timestamp:
- 07/10/2020 10:21:22 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/feed.php
r48322 r48429 520 520 foreach ( (array) $val as $enc ) { 521 521 $enclosure = explode( "\n", $enc ); 522 523 $url = ''; 524 $type = ''; 525 $length = 0; 526 527 $mimes = get_allowed_mime_types(); 528 529 // Parse url 530 if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) { 531 $url = trim( $enclosure[0] ); 532 } 533 534 // Parse length and type 535 foreach ( range( 1, 2 ) as $i ) { 536 if ( isset( $enclosure[ $i ] ) ) { 537 if ( is_numeric( $enclosure[ $i ] ) ) { 538 $length = trim( $enclosure[ $i ] ); 539 } elseif ( in_array( $enclosure[ $i ], $mimes ) ) { 540 $type = trim( $enclosure[ $i ] ); 541 } 542 } 543 } 544 545 $html_link_tag = sprintf( 546 "<link href=\"%s\" rel=\"enclosure\" length=\"%d\" type=\"%s\" />\n", 547 esc_url( $url ), 548 esc_attr( $length ), 549 esc_attr( $type ) 550 ); 522 551 /** 523 552 * Filters the atom enclosure HTML link tag for the current post. … … 527 556 * @param string $html_link_tag The HTML link tag with a URI and other attributes. 528 557 */ 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");558 echo apply_filters( 'atom_enclosure', $html_link_tag ); 530 559 } 531 560 } -
trunk/tests/phpunit/tests/feed/atom.php
r47198 r48429 206 206 } 207 207 } 208 209 /** 210 * @test 33591 211 */ 212 function test_atom_enclosure_with_extended_url_length_type_parsing() { 213 $enclosures = array( 214 array( 215 'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465\nvideo/mp4", // url length type 216 'expected' => array( 217 'href' => 'https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4', 218 'length' => 318465, 219 'type' => 'video/mp4', 220 ), 221 ), 222 array( 223 'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\nvideo/mp4\n318465", // url type length 224 'expected' => array( 225 'href' => 'https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4', 226 'length' => 318465, 227 'type' => 'video/mp4', 228 ), 229 ), 230 array( 231 'actual' => "https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4\n318465", // url length 232 'expected' => array( 233 'href' => 'https://wordpress.dev/wp-content/uploads/2017/09/movie.mp4', 234 'length' => 318465, 235 'type' => '', 236 ), 237 ), 238 array( 239 'actual' => "https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3\n\naudio/mpeg", // url type 240 'expected' => array( 241 'href' => 'https://wordpress.dev/wp-content/uploads/2017/01/audio.mp3', 242 'length' => 0, 243 'type' => 'audio/mpeg', 244 ), 245 ), 246 array( 247 'actual' => 'https://wordpress.dev/wp-content/uploads/2016/01/test.mp4', // url 248 'expected' => array( 249 'href' => 'https://wordpress.dev/wp-content/uploads/2016/01/test.mp4', 250 'length' => 0, 251 'type' => '', 252 ), 253 ), 254 ); 255 256 $post_id = end( self::$posts ); 257 foreach ( $enclosures as $enclosure ) { 258 add_post_meta( $post_id, 'enclosure', $enclosure['actual'] ); 259 } 260 $this->go_to( '/?feed=atom' ); 261 $feed = $this->do_atom(); 262 $xml = xml_to_array( $feed ); 263 $entries = xml_find( $xml, 'feed', 'entry' ); 264 $entries = array_slice( $entries, 0, 1 ); 265 266 foreach ( $entries as $key => $entry ) { 267 $links = xml_find( $entries[ $key ]['child'], 'link' ); 268 $i = 0; 269 foreach ( (array) $links as $link ) { 270 if ( 'enclosure' == $link['attributes']['rel'] ) { 271 $this->assertEquals( $enclosures[ $i ]['expected']['href'], $link['attributes']['href'] ); 272 $this->assertEquals( $enclosures[ $i ]['expected']['length'], $link['attributes']['length'] ); 273 $this->assertEquals( $enclosures[ $i ]['expected']['type'], $link['attributes']['type'] ); 274 $i++; 275 } 276 } 277 } 278 } 208 279 }
Note: See TracChangeset
for help on using the changeset viewer.