Skip to:

Opened 7 years ago

Closed 7 years ago

Last modified 3 years ago

#7484 closed defect (bug) (fixed)

Resize member avatar error with cyrillic (not latin) filename

Reported by: snookerist's profile snookerist Owned by: r-a-y's profile r-a-y
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.3.0
Component: Core Keywords: has-patch


When user upload user avatar the system offers to resize image.

If uploaded image filename contains cyrillic (not latin) characters, then appears error, meaning that error was occured on image resizing (При изменении размеров вашей картинки профиля произошла ошибка.).

If user upload image with filename containing only latic characters (not cyrillic) operation be done successfull.

I use the last version of WordPress and BuddyPress.
System language is russian.

Attachments (2)

7484.iconv.patch (1.4 KB) - added by r-a-y 7 years ago.
7484.01.patch (1.7 KB) - added by r-a-y 7 years ago.

Download all attachments as: .zip

Change History (13)

#1 @pirs
7 years ago

Hello, I also have this problem. Please help me solve it.

WordPress 4.7.4 , BuddyPress 2.8.2

Last edited 7 years ago by pirs (previous) (diff)

This ticket was mentioned in Slack in #buddypress by hnla. View the logs.

7 years ago

#3 @r-a-y
7 years ago

  • Keywords has-patch added
  • Version changed from 2.8.2 to 2.3.0

The problem is mostly with WordPress not properly converting utf-8 filenames to an ASCII version.

See #WP22363, #WP24661, #WP15955.

We can wait for WordPress to fix this or we can put in a temporary fix.

iconv.patch will try to convert any utf-8 characters in the filename to their ASCII equivalent. This should fix the immediate issue with our uploader class, but relies on iconv, which might not be available and is a little finicky depending on the system.

Could try using mb_convert_encoding() as well. Or if remove_accents() worked properly, we could do the following:

add_filter( 'sanitize_file_name', 'remove_accents' );

An alternative method would be using URLify against our filenames:

But that will require adding another external library.

Last edited 7 years ago by r-a-y (previous) (diff)

7 years ago

#4 @hnla
7 years ago

Given your comments above & that this is really a root issue in WP...

<snip> but relies on iconv

As it's an extension to PHP & as you say which might not be available I think that rules this out as a fix?

mb_convert_encoding() possibly?

Adding an external library sounds like a bad idea given that WP ought to/will fix at some point.

If this causes issues for WP sites in general then we are fixing sites for images in one small respect while leaving the wider issue existing which seems odd to me, the sites are broken for images regardless of what we do?

I find this an odd issue given WP places importance on internationalization yet that last ticket is years old!

I am proposing we close this as a 'wontfix', r-a-y you prompted on the WP ticket and I think we need to leave it there but I leave that decision to you :)

#5 @r-a-y
7 years ago

WordPress uses iconv() in one of their functions, wp_check_invalid_utf8():

I think it's safe for us to use it as well, since we should support all languages as much as possible until WordPress offers better support for transliteration in remove_accents():

7 years ago

#6 @r-a-y
7 years ago

  • Milestone changed from Awaiting Review to Under Consideration

01.patch makes use of a PHP 5.4 function called transliterator_transliterate() if available. That function also works if the PECL intl is installed.

If not available, we use WP's remove_accents(), which covers quite a few languages, but not all like Cyrillic. After that, if the filename still has some utf8 characters, we use iconv() if it exists.

This ticket was mentioned in Slack in #buddypress by r-a-y. View the logs.

7 years ago

#8 @hnla
7 years ago

  • Milestone changed from Under Consideration to 2.9

This ticket was mentioned in Slack in #buddypress by hnla. View the logs.

7 years ago

This ticket was mentioned in Slack in #buddypress by r-a-y. View the logs.

7 years ago

#11 @r-a-y
7 years ago

  • Owner set to r-a-y
  • Resolution set to fixed
  • Status changed from new to closed

In 11602:

Attachments: Fix issues with uploading a file containing accented characters.

Previously, when uploading a new avatar or cover image with accented
characters, the upload would fail. This is due to an upstream WordPress
bug since WP does not handle sanitizing these types of file names properly.
(See #WP22363, #WP24661, #WP15955 for just a few of the related problems.)

To fix this in BuddyPress, we are putting in a workaround to convert file
names with UTF-8 characters to their ASCII equivalent. First, we try to
use PHP's intl extension if available. If not, we use WP's
remove_accents() function, and lastly if the filename still contains
UTF-8 characters, we also try to use iconv() if available.

This is considered a workaround until WordPress fixes this in core.

Fixes #7484.

Note: See TracTickets for help on using tickets.