Patch #6416 ยป repositories_controller.patch
app/controllers/repositories_controller.rb 2010-09-15 06:48:44.000000000 +0900 | ||
---|---|---|
18 | 18 |
require 'SVG/Graph/Bar' |
19 | 19 |
require 'SVG/Graph/BarHorizontal' |
20 | 20 |
require 'digest/sha1' |
21 |
require 'iconv' |
|
21 | 22 | |
22 | 23 |
class ChangesetNotFound < Exception; end |
23 | 24 |
class InvalidRevisionParam < Exception; end |
... | ... | |
121 | 122 | |
122 | 123 |
@content = @repository.cat(@path, @rev) |
123 | 124 |
(show_error_not_found; return) unless @content |
124 |
if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte)
|
|
125 |
if 'raw' == params[:format] || is_binary?(@content) || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte)
|
|
125 | 126 |
# Force the download |
126 | 127 |
send_data @content, :filename => @path.split('/').last |
127 | 128 |
else |
... | ... | |
303 | 304 |
graph.burn |
304 | 305 |
end |
305 | 306 | |
307 |
def is_binary?(data) |
|
308 |
return true if data =~ /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/n |
|
309 |
begin |
|
310 |
Iconv.iconv('utf-8', 'utf-8', data) |
|
311 |
return false |
|
312 |
rescue |
|
313 |
return true |
|
314 |
end |
|
315 |
end |
|
316 | ||
306 | 317 |
end |
307 | 318 |
|
308 | 319 |
class Date |