Defect #1243

Uploading of attachment with Non-ascii filename fails when host on windows

Added by Chaoqun Zou over 9 years ago. Updated over 9 years ago.

Status:ClosedStart date:2008-05-15
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Attachments
Target version:-
Resolution: Affected version:

Description

When redmine is hosted on windows, if the uploaded attachement's file-name is Non-ascii(eg. Chinese, Japanese..), there will be an exception of invalid-argument and the uploading will fail.
The attachemented picture shows the error page.

I have found what caused this error(from the ruby way, second edition):

There are other OS issues relating to character conversion. Suppose that the operating system on which Ruby is running is set to a non-UTF-8 locale, or Ruby doesn't use UTF-8 to communicate with the OS (as is the case with the Win32 package). Then there are additional complications.
For example, Windows supports Unicode filenames and uses Unicode internally. But Ruby at the present time communicates with Windows through the legacy code page. In the case of English and most other western European editions, this is code page 1252 (or WINDOWS-1252).
You can still use UTF-8 inside your application, but you'll need to convert to the legacy code page to specify filenames. This can be done using iconv, but it's important to remember that the legacy code page can describe only a small subset of the characters available in Unicode.
In addition, this means that Ruby on Windows cannot, at present, open existing files whose names cannot be described in the legacy code page. This restriction does not apply to Mac OS X, Linux, or other systems using UTF-8 locales.

And, If modify the attachment.rb like the following, I can resolve my problem when host redmine on a Chinese version Windows server.
I am wondering that if there exist an common way to resolve this problem for the windows users?
I think if I can determine the host os is windows(easy) and the filename is Non-ascii(difficult?), then I can do some converting work like the following.

Index: attachment.rb
--- attachment.rb Base (BASE)
+++ attachment.rb Locally Modified (Based On LOCAL)
@ -75,7 +75,8 @

  1. Returns file's location on disk
    def diskfile
    - "#{@storage_path}/#{self.disk_filename}"
    + filename = "#{
    @storage_path}/#{self.disk_filename}"
    + Iconv.new("gbk", "utf-8").iconv(filename)
    end

cn_file_err.JPG (76.7 KB) Chaoqun Zou, 2008-05-15 17:02


Related issues

Duplicates Redmine - Defect #1089: attachement's name maybe invalid. Closed 2008-04-23

Associated revisions

Revision 1433
Added by Jean-Philippe Lang over 9 years ago

Fixed: possible error when attachment's filename is non-ASCII (#747, #1243, #1089).

History

#1 Updated by Jean-Philippe Lang over 9 years ago

  • Status changed from New to Closed

Fixed in r1433. Filename will be hashed if needed.

Also available in: Atom PDF