diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb
index d82e1656..41218fa7 100644
--- a/app/helpers/repositories_helper.rb
+++ b/app/helpers/repositories_helper.rb
@@ -17,13 +17,27 @@
require 'coderay'
require 'coderay/helpers/file_type'
+require 'iconv'
module RepositoriesHelper
def syntax_highlight(name, content)
type = CodeRay::FileType[name]
type ? CodeRay.scan(content, type).html : h(content)
end
-
+
+ def to_utf8(str)
+ return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
+ @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
+ @encodings.each do |encoding|
+ begin
+ return Iconv.conv('UTF-8', encoding, str)
+ rescue Iconv::Failure
+ # do nothing here and try the next encoding
+ end
+ end
+ str
+ end
+
def repository_field_tags(form, repository)
method = repository.class.name.demodulize.underscore + "_field_tags"
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
diff --git a/app/views/repositories/diff.rhtml b/app/views/repositories/diff.rhtml
index e982b6e1..5094f471 100644
--- a/app/views/repositories/diff.rhtml
+++ b/app/views/repositories/diff.rhtml
@@ -34,13 +34,13 @@
<%= table_file[key].nb_line_left %>
- <%= table_file[key].line_left %>
+ <%=to_utf8 table_file[key].line_left %>
|
<%= table_file[key].nb_line_right %>
|
- <%= table_file[key].line_right %>
+ <%=to_utf8 table_file[key].line_right %>
|
<% end %>
@@ -72,11 +72,11 @@
<% if table_file[key].line_left.empty? %>
- <%= table_file[key].line_right %>
+ <%=to_utf8 table_file[key].line_right %>
|
<% else %>
- <%= table_file[key].line_left %>
+ <%=to_utf8 table_file[key].line_left %>
|
<% end %>
diff --git a/app/views/repositories/entry.rhtml b/app/views/repositories/entry.rhtml
index 7d8cbb31..94db240a 100644
--- a/app/views/repositories/entry.rhtml
+++ b/app/views/repositories/entry.rhtml
@@ -9,7 +9,7 @@
<% line_num = 1 %>
- <% syntax_highlight(@path, @content).each_line do |line| %>
+ <% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
<%= line_num %> |
<%= line %> |
diff --git a/app/views/settings/edit.rhtml b/app/views/settings/edit.rhtml
index c3e430c9..2accdc71 100644
--- a/app/views/settings/edit.rhtml
+++ b/app/views/settings/edit.rhtml
@@ -48,6 +48,9 @@
<%= check_box_tag 'settings[sys_api_enabled]', 1, Setting.sys_api_enabled? %><%= hidden_field_tag 'settings[sys_api_enabled]', 0 %>
+
+
+<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %>
<%= l(:text_comma_separated) %>