summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-01-01 13:40:36 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-01-01 13:40:36 +0000
commit488285e12321fc590dee0235470cfb12d77a3432 (patch)
treed8f44a7dad87372748a64e12cedf66148c0e85f9 /app
parent1c7079db3fb099c6913353c9d56c27628b712026 (diff)
downloadredmine-488285e12321fc590dee0235470cfb12d77a3432.tar.gz
redmine-488285e12321fc590dee0235470cfb12d77a3432.zip
Strip non utf8 content when displaying diff (ruby1.9 compatibility).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4604 e93f8b46-1217-0410-a6f0-8f06a7374b81
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 -%>