Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#47889 new defect (bug)

uploading image contains special characters will return a wrong image url

Reported by: sockscap64's profile sockscap64 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.2.2
Component: Media Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

How to reproduce this bug?
1> ready an image, make sure it contains a special character, such as ^. In my case, this image file is test^image.jpg
2> goto page 'Upload New Media', that is './wp-admin/media-new.php'
3> select your image file and upload it.
4> in the completion list, you will see a thumbnail and the image that you uploaded. (see attachment )
5> the thumbnail is broken, and the URL of the thumbnail is '.../testimage.jpg'. actually, it's should be '.../test^image.jpg'

Attachments (2)

Untitled.png (4.5 KB) - added by sockscap64 5 years ago.
47889.diff (694 bytes) - added by donmhico 5 years ago.

Download all attachments as: .zip

Change History (5)

@sockscap64
5 years ago

#1 @SergeyBiryukov
5 years ago

  • Description modified (diff)

@donmhico
5 years ago

#2 follow-up: @donmhico
5 years ago

  • Keywords has-patch added

Hello @sockscap64,

Welcome to our trac. Thank you for your bug report. I confirmed the bug on my side as well and I attached a patch that fixes it.

In my attached patch, 47889.diff, you'll see that I removed the wrapping esc_url(). I think it's safe to do this since the image url comes from wp_get_attachment_image_src() which is expected to return an array with a url as the first element if the image exist.

Reference:
https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/

Last edited 5 years ago by donmhico (previous) (diff)

#3 in reply to: ↑ 2 @sockscap64
5 years ago

Thank you so much.@donmhico

Replying to donmhico:

Hello @sockscap64,

Welcome to our trac. Thank you for your bug report. I confirmed the bug on my side as well and I attached a patch that fixes it.

In my attached patch, 47889.diff, you'll see that I removed the wrapping esc_url(). I think it's safe to do this since the image url comes from wp_get_attachment_image_src() which is expected to return an array with a url as the first element if the image exist.

Reference:
https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/

Note: See TracTickets for help on using tickets.