WordPress.org

Make WordPress Core

Opened 17 months ago

Closed 17 months ago

Last modified 17 months ago

#49944 closed enhancement (duplicate)

media_sideload_image() fails with no file extension.

Reported by: secondlinethemes Owned by:
Milestone: Priority: normal
Severity: minor Version: 5.4
Component: Media Keywords: needs-patch
Focuses: Cc:

Description

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.

Change History (2)

#1 @SergeyBiryukov
17 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac!

Thank for the report, we're already tracking this issue in #18730.

#2 @secondlinethemes
17 months ago

Thanks @SergeyBiryukov, and sorry for the dupe!

Note: See TracTickets for help on using tickets.