scm: fix non ascii text files displaying (#6256).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5204 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
0597adfe53
commit
79eba572af
@ -123,17 +123,32 @@ class RepositoriesController < ApplicationController
|
|||||||
|
|
||||||
@content = @repository.cat(@path, @rev)
|
@content = @repository.cat(@path, @rev)
|
||||||
(show_error_not_found; return) unless @content
|
(show_error_not_found; return) unless @content
|
||||||
if 'raw' == params[:format] || @content.is_binary_data? ||
|
if 'raw' == params[:format] ||
|
||||||
(@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte)
|
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
|
||||||
|
! is_entry_text_data?(@content, @path)
|
||||||
# Force the download
|
# Force the download
|
||||||
send_data @content, :filename => filename_for_content_disposition(@path.split('/').last)
|
send_data @content, :filename => filename_for_content_disposition(@path.split('/').last)
|
||||||
else
|
else
|
||||||
# Prevent empty lines when displaying a file with Windows style eol
|
# Prevent empty lines when displaying a file with Windows style eol
|
||||||
|
# TODO: UTF-16
|
||||||
|
# Is this needs? AttachmentsController reads file simply.
|
||||||
@content.gsub!("\r\n", "\n")
|
@content.gsub!("\r\n", "\n")
|
||||||
@changeset = @repository.find_changeset_by_name(@rev)
|
@changeset = @repository.find_changeset_by_name(@rev)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_entry_text_data?(ent, path)
|
||||||
|
# UTF-16 contains "\x00".
|
||||||
|
# It is very strict that file contains less than 30% of ascii symbols
|
||||||
|
# in non Western Europe.
|
||||||
|
return true if Redmine::MimeType.is_type?('text', path)
|
||||||
|
# Ruby 1.8.6 has a bug of integer divisions.
|
||||||
|
# http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
|
||||||
|
return false if ent.is_binary_data?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
private :is_entry_text_data?
|
||||||
|
|
||||||
def annotate
|
def annotate
|
||||||
@entry = @repository.entry(@path, @rev)
|
@entry = @repository.entry(@path, @rev)
|
||||||
(show_error_not_found; return) unless @entry
|
(show_error_not_found; return) unless @entry
|
||||||
|
Loading…
x
Reference in New Issue
Block a user