diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 367976515cde3abeddf85950cfcedc2b900a9f1d..0fce8c95be89d48b17674d6dfa25f9694f44fc18 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -28,7 +28,7 @@ module AttachmentsHelper end end - def to_utf8(str) + def to_utf8_for_attachments(str) if str.respond_to?(:force_encoding) str.force_encoding('UTF-8') return str if str.valid_encoding? diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index c8f6e8bfaf3ba8526667e15d7c4ee94ec0f71396..a007def08b18261af38f6a2f0576f4647fe84b67 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -116,7 +116,7 @@ module RepositoriesHelper output end - def to_utf8(str) + def to_utf8_for_repositories(str) return str if str.nil? str = to_utf8_internal(str) if str.respond_to?(:force_encoding) diff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rb index d314a96f40f0b6bc099b67586799b378b280c968..1fad5fe5ac767f26e9121295e56643a6a3d55c54 100644 --- a/app/helpers/timelog_helper.rb +++ b/app/helpers/timelog_helper.rb @@ -144,7 +144,7 @@ module TimelogHelper headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) } headers += periods headers << l(:label_total) - csv << headers.collect {|c| to_utf8(c) } + csv << headers.collect {|c| to_utf8_for_timelogs(c) } # Content report_criteria_to_csv(csv, criterias, periods, hours) # Total row @@ -166,7 +166,7 @@ module TimelogHelper hours_for_value = select_hours(hours, criterias[level], value) next if hours_for_value.empty? row = [''] * level - row << to_utf8(format_criteria_value(criterias[level], value)) + row << to_utf8_for_timelogs(format_criteria_value(criterias[level], value)) row += [''] * (criterias.length - level - 1) total = 0 periods.each do |period| @@ -183,7 +183,7 @@ module TimelogHelper end end - def to_utf8(s) + def to_utf8_for_timelogs(s) @ic ||= Iconv.new(l(:general_csv_encoding), 'UTF-8') begin; @ic.iconv(s.to_s); rescue; s.to_s; end end diff --git a/app/views/common/_diff.rhtml b/app/views/common/_diff.rhtml index 03b06a0cec522302fd0bb8e244c61c77e47812c7..f7f40fb04fa4e3f329b31e3cdb42bedf76ad412e 100644 --- a/app/views/common/_diff.rhtml +++ b/app/views/common/_diff.rhtml @@ -31,7 +31,7 @@ <% else -%> <table class="filecontent"> <thead> -<tr><th colspan="3" class="filename"><%=to_utf8 table_file.file_name %></th></tr> +<tr><th colspan="3" class="filename"><%=to_utf8_for_attachments table_file.file_name %></th></tr> </thead> <tbody> <% table_file.each_line do |spacing, line| %> @@ -44,7 +44,7 @@ <th class="line-num"><%= line.nb_line_left %></th> <th class="line-num"><%= line.nb_line_right %></th> <td class="line-code <%= line.type_diff %>"> - <pre><%=to_utf8 line.html_line %></pre> + <pre><%=to_utf8_for_attachments line.html_line %></pre> </td> </tr> <% end -%> diff --git a/app/views/common/_file.rhtml b/app/views/common/_file.rhtml index 13ad8bbda921e44dd5771f570e270a9b3b58f25b..6394268cb7b89c71bf5e215b6234fee23f524a91 100644 --- a/app/views/common/_file.rhtml +++ b/app/views/common/_file.rhtml @@ -2,7 +2,7 @@ <table class="filecontent syntaxhl"> <tbody> <% line_num = 1 %> -<% syntax_highlight(filename, to_utf8(content)).each_line do |line| %> +<% syntax_highlight(filename, to_utf8_for_attachments(content)).each_line do |line| %> <tr><th class="line-num" id="L<%= line_num %>"><a href="#L<%= line_num %>"><%= line_num %></a></th><td class="line-code"><pre><%= line %></pre></td></tr> <% line_num += 1 %> <% end %> diff --git a/app/views/repositories/annotate.rhtml b/app/views/repositories/annotate.rhtml index 498507148de0b09b1fc6897bb48fa2fb0b3b67b4..4a2244b66aca26ca4e7081b703eb6afe88ec5750 100644 --- a/app/views/repositories/annotate.rhtml +++ b/app/views/repositories/annotate.rhtml @@ -14,7 +14,7 @@ <table class="filecontent annotate syntaxhl"> <tbody> <% line_num = 1 %> - <% syntax_highlight(@path, to_utf8(@annotate.content)).each_line do |line| %> + <% syntax_highlight(@path, to_utf8_for_repositories(@annotate.content)).each_line do |line| %> <% revision = @annotate.revisions[line_num-1] %> <tr class="bloc-<%= revision.nil? ? 0 : colors[revision.identifier || revision.revision] %>"> <th class="line-num" id="L<%= line_num %>"><a href="#L<%= line_num %>"><%= line_num %></a></th> diff --git a/test/unit/helpers/repository_helper_test.rb b/test/unit/helpers/repository_helper_test.rb index 23067ea5442bc3314c8c142429dbfdb5b86d9a33..ad8c4706a5ff28c15662f0df817589130789332e 100644 --- a/test/unit/helpers/repository_helper_test.rb +++ b/test/unit/helpers/repository_helper_test.rb @@ -20,7 +20,7 @@ require File.expand_path('../../../test_helper', __FILE__) class RepositoryHelperTest < HelperTestCase include RepositoriesHelper - def test_from_latin1_to_utf8 + def test_from_latin1_to_utf8_for_repositories with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do s1 = "Texte encod\xc3\xa9" s2 = "Texte encod\xe9" @@ -30,12 +30,12 @@ class RepositoryHelperTest < HelperTestCase s2.force_encoding("ASCII-8BIT") s3.force_encoding("UTF-8") end - assert_equal s1, to_utf8(s2) - assert_equal s1, to_utf8(s3) + assert_equal s1, to_utf8_for_repositories(s2) + assert_equal s1, to_utf8_for_repositories(s3) end end - def test_from_euc_jp_to_utf8 + def test_from_euc_jp_to_utf8_for_repositories with_settings :repositories_encodings => 'UTF-8,EUC-JP' do s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3" s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3" @@ -45,12 +45,12 @@ class RepositoryHelperTest < HelperTestCase s2.force_encoding("ASCII-8BIT") s3.force_encoding("UTF-8") end - assert_equal s1, to_utf8(s2) - assert_equal s1, to_utf8(s3) + assert_equal s1, to_utf8_for_repositories(s2) + assert_equal s1, to_utf8_for_repositories(s3) end end - def test_to_utf8_should_be_converted_all_latin1_to_utf8 + def test_to_utf8_for_repositories_should_be_converted_all_latin1_to_utf8 with_settings :repositories_encodings => 'ISO-8859-1' do s1 = "\xc3\x82\xc2\x80" s2 = "\xC2\x80" @@ -60,25 +60,25 @@ class RepositoryHelperTest < HelperTestCase s2.force_encoding("ASCII-8BIT") s3.force_encoding("UTF-8") end - assert_equal s1, to_utf8(s2) - assert_equal s1, to_utf8(s3) + assert_equal s1, to_utf8_for_repositories(s2) + assert_equal s1, to_utf8_for_repositories(s3) end end - def test_to_utf8_blank_string - assert_equal "", to_utf8("") - assert_equal nil, to_utf8(nil) + def test_to_utf8_for_repositories_blank_string + assert_equal "", to_utf8_for_repositories("") + assert_equal nil, to_utf8_for_repositories(nil) end - def test_to_utf8_returns_ascii_as_utf8 + def test_to_utf8_for_repositories_returns_ascii_as_utf8 s1 = "ASCII" s2 = s1.dup if s1.respond_to?(:force_encoding) s1.force_encoding("UTF-8") s2.force_encoding("ISO-8859-1") end - str1 = to_utf8(s1) - str2 = to_utf8(s2) + str1 = to_utf8_for_repositories(s1) + str2 = to_utf8_for_repositories(s2) assert_equal s1, str1 assert_equal s1, str2 if s1.respond_to?(:force_encoding) @@ -87,10 +87,10 @@ class RepositoryHelperTest < HelperTestCase end end - def test_to_utf8_invalid_utf8_sequences_should_be_stripped + def test_to_utf8_for_repositories_invalid_utf8_sequences_should_be_stripped with_settings :repositories_encodings => '' do s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") - str = to_utf8(s1) + str = to_utf8_for_repositories(s1) if str.respond_to?(:force_encoding) assert_equal "Texte encod? en ISO-8859-1.", str assert str.valid_encoding?