[wp-trac] [WordPress Trac] #63292: atom_enclosure doesn't always get MIME type - inconsistency with rss_enclosure

WordPress Trac noreply at wordpress.org
Wed Apr 16 08:49:47 UTC 2025


#63292: atom_enclosure doesn't always get MIME type - inconsistency with
rss_enclosure
--------------------------+-----------------------------
 Reporter:  edent         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Feeds         |    Version:  6.8
 Severity:  minor         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The function `atom_enclosure()` does not always select MIME types
 correctly. This bug is not present in `rss_enclosure()`

 `rss_enclosure` gets the MIME type like this:
 {{{#!php
 // Only get the first element, e.g. 'audio/mpeg' from 'audio/mpeg mpga mp2
 mp3'.
 $t    = preg_split( '/[ \t]/', trim( $enclosure[2] ) );
 $type = $t[0];
 }}}

 The equivalent `atom_enclosure` is more complex, brittle, and subtly
 different:

 {{{#!php
 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, true ) ) {
       $type = trim( $enclosure[ $i ] );
     }
   }
 }
 }}}

 If I var_export the `$enclosure` variable in the `atom_enclosure()`
 function, this is what I see:


 {{{
 array (
   0 =>
 'https://video.twimg.com/ext_tw_video/1432767873504718850/pu/vid/720x960/sS9cLdGn93eUmvKC.mp4?tag=12',
   1 => '1546364',
   2 => 'video/mp4',
   3 => '',
 )array (
   0 => 'https://shkspr.mobi/blog/wp-content/uploads/2025/03/Move-roomba-
 to-a-new-location.mp3^M',
   1 => '46188^M',
   2 => 'audio/mpeg^M',
   3 => '',
 )
 }}}

 I do not know *why* some of my media has the DOS carriage return at the
 end!

 This can be fixed by trimming the string before checking whether it is in
 the MIME type array:

 {{{#!php
 …
     } elseif ( in_array( trim( $enclosure[ $i ] ), $mimes, true ) ) {
       $type = trim( $enclosure[ $i ] );
     }
 …
 }}}

 Given that the type is trimmed anyway, this seems like a sensible
 precaution.

 A longer-term solution might be to ensure that both rss_enclosure and
 atom_enclosure functions behave in the same way.

 For more details, see https://wordpress.org/support/topic/missing-mime-
 type-using-atom_enclosure/

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63292>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list