Chinaunix

标题: 通过redmine repository看代码的一个问题 [打印本页]

作者: feiyang10086    时间: 2011-02-25 15:22
标题: 通过redmine repository看代码的一个问题
转:jak47


通过redmine repository看代码的一个问题




通过redmine repository看代码,有时候按review按钮,可是浏览器却弹出download画面, 导致不能和看DIFF一样直接在线观看,非常不方便。

经过google搜索, 有人回答原因如下。

ruby中如果string中有超过30%ascii码或者回车换行符以外的字符的话, 就会被认为是二进制数据,导致不能在网页中直接打开,而显示了Download画面。

解决方法

参照以下DIFF文件

Diff代码
  1. Index: app/controllers/repositories_controller.rb   
  2. ===================================================================   
  3. --- app/controllers/repositories_controller.rb    (revision 1709)   
  4. +++ app/controllers/repositories_controller.rb    (working copy)   
  5. @@ -102,7 +102,7 @@   
  6.   
  7.      @content = @repository.cat(@path, @rev)   
  8.      show_error_not_found and return unless @content   
  9. -    if 'raw' == params[:format] || @content.is_binary_data?   
  10. +    if 'raw' == params[:format] || @content.include?("\x00")   
  11.        # Force the download if it's a binary file   
  12.        send_data @content, :filename => @path.split('/').last   
  13.      else   
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2