轉(zhuǎn):jak47
通過redmine repository看代碼的一個問題
通過redmine repository看代碼,有時候按review按鈕,可是瀏覽器卻彈出download畫面, 導(dǎo)致不能和看DIFF一樣直接在線觀看,非常不方便。
經(jīng)過google搜索, 有人回答原因如下。
ruby中如果string中有超過30%ascii碼或者回車換行符以外的字符的話, 就會被認為是二進制數(shù)據(jù),導(dǎo)致不能在網(wǎng)頁中直接打開,而顯示了Download畫面。
解決方法
參照以下DIFF文件
Diff代碼- Index: app/controllers/repositories_controller.rb
- ===================================================================
- --- app/controllers/repositories_controller.rb (revision 1709)
- +++ app/controllers/repositories_controller.rb (working copy)
- @@ -102,7 +102,7 @@
-
- @content = @repository.cat(@path, @rev)
- show_error_not_found and return unless @content
- - if 'raw' == params[:format] || @content.is_binary_data?
- + if 'raw' == params[:format] || @content.include?("\x00")
- # Force the download if it's a binary file
- send_data @content, :filename => @path.split('/').last
- else
復(fù)制代碼 |