summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/helpers/attachments_helper.rb8
-rw-r--r--app/views/common/_diff.rhtml4
2 files changed, 9 insertions, 3 deletions
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index 29cdb9790..50b44890f 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -29,6 +29,12 @@ module AttachmentsHelper
end
def to_utf8(str)
- str
+ return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
+ begin
+ Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
+ rescue Iconv::InvalidEncoding
+ # "UTF-8//IGNORE" is not supported on some OS
+ str
+ end
end
end
diff --git a/app/views/common/_diff.rhtml b/app/views/common/_diff.rhtml
index 546644ded..619790c13 100644
--- a/app/views/common/_diff.rhtml
+++ b/app/views/common/_diff.rhtml
@@ -4,7 +4,7 @@
<% if diff_type == 'sbs' -%>
<table class="filecontent">
<thead>
-<tr><th colspan="4" class="filename"><%= table_file.file_name %></th></tr>
+<tr><th colspan="4" class="filename"><%=to_utf8 table_file.file_name %></th></tr>
</thead>
<tbody>
<% prev_line_left, prev_line_right = nil, nil -%>
@@ -31,7 +31,7 @@
<% else -%>
<table class="filecontent syntaxhl">
<thead>
-<tr><th colspan="3" class="filename"><%= table_file.file_name %></th></tr>
+<tr><th colspan="3" class="filename"><%=to_utf8 table_file.file_name %></th></tr>
</thead>
<tbody>
<% prev_line_left, prev_line_right = nil, nil -%>