attachment from email, filename not displayed correctly for chinese characters
Added by frank li over 14 years ago
there is no problem when attach files to issue in the brower.
However, if the issue is created via incoming email, the attached file name can not be displayed correctly if they
are chinese.
For example, I got something like GB2312_B_RGF0YXN0YWdlOC4xyf28trLiytS94bn7Lnhscw__ .
It seems to me an encoding problem. From above I guess the original file name was encoded via GB2312, but the mysql database is utf8.
I read the code, is it the place that extra the filename of the attachment.
def sanitize_filename(value)
# get only the filename, not the whole path
just_filename = value.gsub(/^.*(\\|\/)/, '')
# NOTE: File.basename doesn't work right with Windows paths on Unix
# INCORRECT: just_filename = File.basename(value.gsub('\\\\', '/'))
# Finally, replace all non alphanumeric, hyphens or periods with underscore
@filename = just_filename.gsub(/[^\w\.\-]/,'_')
end
Any help is appreicated!
Replies (1)
RE: attachment from email, filename not displayed correctly for chinese characters - Added by Denis Yagofarov about 14 years ago
Try this:
just_filename = just_filename.force_encoding('UTF-8')
just_filename = just_filename.gsub(/[^[:word:]\.\-]/,'_')
@filename = just_filename
I'v done simple test (had the same problem with Cyrillic):
$ LC_CTYPE=ru_RU.UTF-8 ruby -e 'puts "a,Ы,b,Ы,c,Ы".gsub(/[^\w]/, "")' abc $ LC_CTYPE=ru_RU.UTF-8 ruby -e 'puts "a,Ы,b,Ы,c,Ы".gsub(/[^[:word:]]/, "")' aЫbЫcЫ
Link to discussion: http://lists.altlinux.org/pipermail/sisyphus/2010-July/348456.html (on Russian)