OpenProject 上传「中文文件名」不能正确显示的问题

从 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 override sanitize_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

参考资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值