WordPress.org

Make WordPress Core

#21217 closed defect (bug) (fixed)

Encoding problems with uploading media files

Reported by: pavelevap Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.4.1
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

Testing media filename: "Žluťoučký kůň.png"

1) WP 3.4.1 (standard Linux webhosting, using Chrome):

So, why is filename displayed without first character?

2) WP 3.4.1 (xampp, Windows computer, Chrome):

In this case I can see this media file only encoded by Javascript (image editing tool), for example on URL http://localhost/wp-admin/admin-ajax.php?action=imgedit-preview&_ajax_nonce=8f7fa9ba05&postid=21249&rand=49045

Attachments (2)

21217.patch (496 bytes) - added by SergeyBiryukov 22 months ago.
21217.2.patch (488 bytes) - added by SergeyBiryukov 22 months ago.

Download all attachments as: .zip

Change History (11)

SergeyBiryukov22 months ago

comment:1 SergeyBiryukov22 months ago

  • Component changed from General to Media
  • Keywords has-patch added

Point 2 is specific to Windows builds of PHP (see ticket:15955:11, #18634, #19842).

Point 1 is caused by basename() usage to get the file name in get_media_item():
http://core.trac.wordpress.org/browser/tags/3.4.1/wp-admin/includes/media.php#L1063

From php.net:

basename() is locale aware, so for it to see the correct basename with multibyte character paths, the matching locale must be set using the setlocale() function.

21217.patch fixes point 1 using one of the workarounds suggested there.

comment:2 follow-up: nacin22 months ago

We also have wp_basename().

SergeyBiryukov22 months ago

comment:3 in reply to: ↑ 2 SergeyBiryukov22 months ago

  • Milestone changed from Awaiting Review to 3.5

Replying to nacin:

We also have wp_basename().

Thanks for the hint, this works too. wp_basename() is used for similar tasks in image_downsize(), image_resize() and a few other places.

comment:4 pavelevap22 months ago

SergeyBiryukov: Thank you, Sergey. I did not notice this ticket related to second point.

comment:5 bpetty18 months ago

21217.2.patch looks good, and is a quick win for fixing point (1), and point (2) is a duplicate of #15955, so if @SergeyBiryukov's patch is applied, we can close out this ticket.

comment:6 bpetty18 months ago

While I didn't add unit tests for get_media_item() patched here (it's way too large of a method to unit test), I did however add unit tests for wp_basename for this situation.

comment:7 bpetty18 months ago

  • Cc bpetty added

comment:8 SergeyBiryukov18 months ago

  • Keywords commit added

comment:9 ryan18 months ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In 22367:

Use wp_basename() instead of basename() so that multibyte characters are not stomped. Props SergeyBiryukov. fixes #21217

Note: See TracTickets for help on using tickets.