[wp-trac] [WordPress Trac] #49944: media_sideload_image() fails with no file extension.

WordPress Trac noreply at wordpress.org
Sat Apr 18 06:26:19 UTC 2020


#49944: media_sideload_image() fails with no file extension.
------------------------------+-----------------------------
 Reporter:  secondlinethemes  |      Owner:  (none)
     Type:  enhancement       |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Media             |    Version:  5.4
 Severity:  minor             |   Keywords:  needs-patch
  Focuses:                    |
------------------------------+-----------------------------
 The {{{media_sideload_image()}}} function is only able to use paths with
 full file extensions (i.e - {{{https://example.com/img/image.jpg}}}).
 However, if a valid image is based in a URL with no extension, it fails.
 (i.e. - {{{https://example.com/img/image}}})

 The extension-less URL can still have a valid image content-type header
 for the image. It fails twice, both in the regex test -
 {{{preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );}}}

 And in the {{{media_handle_sideload}}} function, both times due to a
 "naked" filename.

 Some popular CDN platforms are serving media files this way. (I've also
 seen some serve files with a query right before the extension, i.e -
 {{{https://example/com/img/image?.jpg}}} - this also fails because of the
 regex.

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


More information about the wp-trac mailing list