WordPress.org

Make WordPress Core

Opened 7 weeks ago

Last modified 5 weeks ago

#49841 new defect (bug)

wp_get_attachment_url does not return a url

Reported by: hughie.molloy Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.4
Component: Media Keywords: reporter-feedback
Focuses: Cc:

Description

wp_get_attachment_url returns the base url to the uploads directory suffix with the file path.

The file path is not always a valid url. 'fun image.png' is a valid file name. It's url path is 'fun%20image.png'

I suggest adding the below straight after line 5859 in wp-includes/post.php

		// Convert the file path into a valid URL path
		$file = implode('/', array_map('rawurlencode', explode(DIRECTORY_SEPARATOR, $file)));

Change History (3)

#1 @davidbaumwald
7 weeks ago

  • Component changed from General to Media
  • Focuses template coding-standards removed

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


5 weeks ago

#3 @johnbillion
5 weeks ago

  • Keywords reporter-feedback added

Thanks for the report @hughiemolloy .

Can you provide some steps to reproduce this bug from the beginning?

For example, when I upload an image containing a space in its name it gets converted to a dash (fun image.png becomes fun-image.png at the point where it gets uploaded). How are you uploading an image and retaining the space in its name?

Regardless of this, it does look like rawurlencode should be applied to the file name for correctness.

Note: See TracTickets for help on using tickets.