Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#21217 closed defect (bug) (fixed)

Encoding problems with uploading media files

Reported by: pavelevap's profile pavelevap Owned by: ryan's profile 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 12 years ago.
21217.2.patch (488 bytes) - added by SergeyBiryukov 12 years ago.

Download all attachments as: .zip

Change History (11)

#1 @SergeyBiryukov
12 years 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.

#2 follow-up: @nacin
12 years ago

We also have wp_basename().

#3 in reply to: ↑ 2 @SergeyBiryukov
12 years 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.

#4 @pavelevap
12 years ago

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

#5 @bpetty
12 years 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.

#6 @bpetty
12 years 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.

#7 @bpetty
12 years ago

  • Cc bpetty added

#8 @SergeyBiryukov
12 years ago

  • Keywords commit added

#9 @ryan
12 years 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.