从 2007 年开始用 Redmine,最近半年一直想换一个平台,团队用了三个多月的 Worktile,不太习惯。最近一个月考察了 Trello、Tower、Teambition、OpenProject,最后决定试用 OpenProject 一周。上周六用了七个多小时完成手工配置,简单试用下来,Timeline、Report、Backlogs 等功能都是极好的。
美中不足的是:上传附件如果是「中文文件名」不能正常显示。不会 Ruby 和 Rails,Google 之后通过修改源码的方式解决了这个问题。
修改方案
OpenProject 使用了 CarrierWave 实现上传文件功能,但是 CarrierWave 默认仅支持英语字母、数字、空格
。如果要支持汉语需要重写 sanitize_regexp
方法。
Filenames and unicode chars
Another security issue you should care for is the file names (see Ruby On Rails Security Guide). By default, CarrierWave provides only
English letters, arabic numerals and some symbols as white-listed characters in the file name
. If you want to support local scripts (Cyrillic letters, letters with diacritics and so on), you have to overridesanitize_regexp
method. It should return regular expression which would match all non-allowed symbols.Also make sure that allowing non-latin characters won't cause a compatibility issue with a third-party plugins or client-side software.
知道了解决方法,需要结合 OpenProject 代码才能确认具体修改哪个文件。
A 方案(确认可行)
在 /config/initializers/carrierwave.rb
文件最后添加一行代码
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
B 方案(未确认)
修改 /app/uploaders/fog_file_uploader.rb
和 /app/uploaders/local_file_uploader.rb
文件,添加以下代码:
def sanitize_regexp
/[^0-9\.\-\+_]/
end
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。