@@ -123,17 +123,32 class RepositoriesController < ApplicationController | |||||
123 |
|
123 | |||
124 | @content = @repository.cat(@path, @rev) |
|
124 | @content = @repository.cat(@path, @rev) | |
125 | (show_error_not_found; return) unless @content |
|
125 | (show_error_not_found; return) unless @content | |
126 |
if 'raw' == params[:format] || |
|
126 | if 'raw' == params[:format] || | |
127 |
(@ent |
|
127 | (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || | |
|
128 | ! is_entry_text_data?(@content, @path) | |||
128 | # Force the download |
|
129 | # Force the download | |
129 | send_data @content, :filename => filename_for_content_disposition(@path.split('/').last) |
|
130 | send_data @content, :filename => filename_for_content_disposition(@path.split('/').last) | |
130 | else |
|
131 | else | |
131 | # Prevent empty lines when displaying a file with Windows style eol |
|
132 | # Prevent empty lines when displaying a file with Windows style eol | |
|
133 | # TODO: UTF-16 | |||
|
134 | # Is this needs? AttachmentsController reads file simply. | |||
132 | @content.gsub!("\r\n", "\n") |
|
135 | @content.gsub!("\r\n", "\n") | |
133 | @changeset = @repository.find_changeset_by_name(@rev) |
|
136 | @changeset = @repository.find_changeset_by_name(@rev) | |
134 | end |
|
137 | end | |
135 | end |
|
138 | end | |
136 |
|
139 | |||
|
140 | def is_entry_text_data?(ent, path) | |||
|
141 | # UTF-16 contains "\x00". | |||
|
142 | # It is very strict that file contains less than 30% of ascii symbols | |||
|
143 | # in non Western Europe. | |||
|
144 | return true if Redmine::MimeType.is_type?('text', path) | |||
|
145 | # Ruby 1.8.6 has a bug of integer divisions. | |||
|
146 | # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F | |||
|
147 | return false if ent.is_binary_data? | |||
|
148 | true | |||
|
149 | end | |||
|
150 | private :is_entry_text_data? | |||
|
151 | ||||
137 | def annotate |
|
152 | def annotate | |
138 | @entry = @repository.entry(@path, @rev) |
|
153 | @entry = @repository.entry(@path, @rev) | |
139 | (show_error_not_found; return) unless @entry |
|
154 | (show_error_not_found; return) unless @entry |
General Comments 0
You need to be logged in to leave comments.
Login now