Defect #1243
closedUploading of attachment with Non-ascii filename fails when host on windows
0%
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
@
- Returns file's location on disk
def diskfile
- "#{@storage_path}/#{self.disk_filename}"
@storage_path}/#{self.disk_filename}"
+ filename = "#{
+ Iconv.new("gbk", "utf-8").iconv(filename)
end
Files
Related issues