diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index 75663689e..0bfe6b4b4 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -1,12 +1,10 @@ # -*- encoding : utf-8 -*- class Git::BlobsController < Git::BaseController - before_filter :set_path - before_filter :set_commit_hash before_filter :find_tree + before_filter :set_path_blob + before_filter :set_commit_hash def show - @blob = @tree / @path - if params[:raw] image_url = Rails.root.to_s + "/" + @path @@ -19,21 +17,18 @@ class Git::BlobsController < Git::BaseController end def blame - @blob = @tree / @path - @blame = Grit::Blob.blame(@git_repository.repo, @commit.try(:id), @path) end def raw - @blob = @tree / @path - headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"] render :text => @blob.data, :content_type => @blob.mime_type end protected - def set_path + def set_path_blob @path = params[:path] + @blob = @tree / @path.encode_to_default end def set_commit_hash diff --git a/app/helpers/commit_helper.rb b/app/helpers/commit_helper.rb index 8093043b3..180374610 100644 --- a/app/helpers/commit_helper.rb +++ b/app/helpers/commit_helper.rb @@ -13,7 +13,7 @@ module CommitHelper end res << "" - res.join("\n").html_safe + res.join("\n").encode_to_default.html_safe end # def format_commit_message(message) @@ -34,7 +34,7 @@ module CommitHelper def short_commit_message(message) # Why 42? Because it is the Answer! - truncate(message, :length => 42, :omission => "...") + truncate(message, :length => 42, :omission => "...").encode_to_default end end diff --git a/app/helpers/git_helper.rb b/app/helpers/git_helper.rb index 619376dd2..f302b5aed 100644 --- a/app/helpers/git_helper.rb +++ b/app/helpers/git_helper.rb @@ -26,7 +26,7 @@ module GitHelper res = "#{link_to @project.name, tree_path(@project)} /" end - res.html_safe + res.encode_to_default.html_safe end def render_line_numbers(n) @@ -38,7 +38,9 @@ module GitHelper def render_blob(blob) res = "" - blob.data.split("\n").collect{|line| "
#{line.present? ? h(line) : "
"}
"}.join + blob.data.encode_to_default.split("\n").collect do |line| + "
#{line.present? ? h(line) : "
"}
" + end.join end def choose_render_way(blob) @@ -46,4 +48,9 @@ module GitHelper return :text if blob.mime_type.match(/text|xml|json/) :binary end + + def force_encoding_to_site(string) + string.dup.encode_to_default + end + end diff --git a/app/views/git/blobs/blame.html.haml b/app/views/git/blobs/blame.html.haml index c39582dd1..aaf184b15 100644 --- a/app/views/git/blobs/blame.html.haml +++ b/app/views/git/blobs/blame.html.haml @@ -29,7 +29,9 @@ - @blame.each do |elem| %tr %td.message{ :rowspan => elem[1].length } - .commit #{link_to shortest_hash_id(elem[0].id), commit_path(@project, elem[0].id)} by #{elem[0].author} #{elem[0].author != elem[0].committer ? "(#{elem[0].committer})" : "" } + .commit + #{link_to shortest_hash_id(elem[0].id), commit_path(@project, elem[0].id)} by + #{elem[0].author.to_s.encode_to_default} #{elem[0].author != elem[0].committer ? "(#{elem[0].committer.to_s.encode_to_default})" : "" } .message %span.date= commit_date(elem[0].committed_date) %span.message= short_commit_message(elem[0].message) @@ -40,7 +42,7 @@ %td.code %pre - %div= elem[1].first + %div= elem[1].first.encode_to_default - elem[1][1..-1].each do |line| %tr @@ -49,6 +51,6 @@ - index += 1 %td.code %pre - %div= line + %div= line.encode_to_default -- content_for :sidebar, render(:partial => 'git/shared/sidebar') \ No newline at end of file +- content_for :sidebar, render(:partial => 'git/shared/sidebar') diff --git a/app/views/git/blobs/show.html.haml b/app/views/git/blobs/show.html.haml index 04b3a19b3..43127ac7e 100644 --- a/app/views/git/blobs/show.html.haml +++ b/app/views/git/blobs/show.html.haml @@ -49,7 +49,7 @@ %td.blob :plain
-
#{ link_to @blob.basename, raw_path(@project, @treeish, @path) }
+
#{ link_to @blob.basename.encode_to_default, raw_path(@project, @treeish, @path) }

- content_for :sidebar, render(:partial => 'git/shared/sidebar') diff --git a/app/views/git/commits/_commit_diff.html.haml b/app/views/git/commits/_commit_diff.html.haml index 5d387b06a..05f68c621 100644 --- a/app/views/git/commits/_commit_diff.html.haml +++ b/app/views/git/commits/_commit_diff.html.haml @@ -2,13 +2,13 @@ .content .inner - %a{ :name => h(commit_diff.a_path) } + %a{ :name => h(commit_diff.a_path.encode_to_default) } .blob_header - .size= h(commit_diff.a_path) + .size= h(commit_diff.a_path.encode_to_default) - if commit_diff.b_path.present? .buttons - = link_to("view file @ #{short_hash_id(@commit.id)}", blob_commit_path(@project, @commit.id, commit_diff.b_path)) + = link_to("view file @ #{short_hash_id(@commit.id)}", blob_commit_path(@project, @commit.id, commit_diff.b_path.encode_to_default)) .clear .diff_data diff --git a/app/views/git/commits/_commits.html.haml b/app/views/git/commits/_commits.html.haml index b248234eb..9e4d9ae50 100644 --- a/app/views/git/commits/_commits.html.haml +++ b/app/views/git/commits/_commits.html.haml @@ -4,12 +4,12 @@ %table %tr %td.committers - .author #{commit.author}, #{commit_date(commit.authored_date)} + .author #{commit.author.to_s.encode_to_default}, #{commit_date(commit.authored_date)} - if commit.committer != commit.author .committer - (committed by: #{commit.committer}, #{commit_date(commit.committed_date)}) + (committed by: #{commit.committer.to_s.encode_to_default}, #{commit_date(commit.committed_date)}) %td.message - %p= link_to commit.message, commit_path(@project, commit.id) + %p= link_to commit.message.encode_to_default, commit_path(@project, commit.id) %td.trees .commit Commit: @@ -23,4 +23,4 @@ .parent Parent: %span{ :style => "float: right;"} - #{link_to short_hash_id(parent.id), tree_path(@project, :treeish => parent.id)} \ No newline at end of file + #{link_to short_hash_id(parent.id), tree_path(@project, :treeish => parent.id)} diff --git a/app/views/git/repositories/show.html.haml b/app/views/git/repositories/show.html.haml index a0e547531..41c205ebd 100644 --- a/app/views/git/repositories/show.html.haml +++ b/app/views/git/repositories/show.html.haml @@ -37,10 +37,10 @@ = image_tag("git/icons/folder_16.png") %td.tree_element - if entry.is_a?(Grit::Blob) - = link_to entry.name, blob_path(@project, @treeish, File.join([@path, entry.name].compact)) + = link_to entry.name.encode_to_default, blob_path(@project, @treeish, File.join([@path, entry.name.encode_to_default].compact)) - else - = link_to "#{entry.name}/", tree_path(@project, @treeish, File.join([@path, entry.name].compact)) + = link_to "#{entry.name.encode_to_default}/", tree_path(@project, @treeish, File.join([@path, entry.name.encode_to_default].compact)) %td==   %td.last==   -- content_for :sidebar, render(:partial => 'git/shared/sidebar') \ No newline at end of file +- content_for :sidebar, render(:partial => 'git/shared/sidebar') diff --git a/config/initializers/core.rb b/config/initializers/core.rb new file mode 100644 index 000000000..fe7ee4f48 --- /dev/null +++ b/config/initializers/core.rb @@ -0,0 +1 @@ +require './lib/ext/core/string' diff --git a/lib/ext/core/string.rb b/lib/ext/core/string.rb new file mode 100644 index 000000000..1810ec2f7 --- /dev/null +++ b/lib/ext/core/string.rb @@ -0,0 +1,5 @@ +class String + def encode_to_default + force_encoding(Encoding.default_internal || Encoding::UTF_8) + end +end