diff options
author | Go MAEDA <maeda@farend.jp> | 2019-03-19 15:43:55 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2019-03-19 15:43:55 +0000 |
commit | 26509e7f4c6dae94baf291b95d46eb6ec8ebca0b (patch) | |
tree | eca8843de4ca00c229612e8f4f323a5474444a29 /test/unit/lib | |
parent | 7d2f10ccac0e51a8eb337ed388ab8182df4c25e1 (diff) | |
download | redmine-26509e7f4c6dae94baf291b95d46eb6ec8ebca0b.tar.gz redmine-26509e7f4c6dae94baf291b95d46eb6ec8ebca0b.zip |
Decode hexadecimal-encoded literals in order to be frozen string literals friendly (#31004).
Patch by Yuichi HARADA.
git-svn-id: http://svn.redmine.org/redmine/trunk@17991 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/lib')
-rw-r--r-- | test/unit/lib/redmine/codeset_util_test.rb | 27 | ||||
-rw-r--r-- | test/unit/lib/redmine/export/csv_test.rb | 3 | ||||
-rw-r--r-- | test/unit/lib/redmine/export/pdf_test.rb | 22 | ||||
-rw-r--r-- | test/unit/lib/redmine/i18n_test.rb | 15 | ||||
-rw-r--r-- | test/unit/lib/redmine/scm/adapters/git_adapter_test.rb | 7 | ||||
-rw-r--r-- | test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb | 9 | ||||
-rw-r--r-- | test/unit/lib/redmine/unified_diff_test.rb | 37 |
7 files changed, 48 insertions, 72 deletions
diff --git a/test/unit/lib/redmine/codeset_util_test.rb b/test/unit/lib/redmine/codeset_util_test.rb index c3040b553..7ae502cba 100644 --- a/test/unit/lib/redmine/codeset_util_test.rb +++ b/test/unit/lib/redmine/codeset_util_test.rb @@ -23,8 +23,8 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase def test_to_utf8_by_setting_from_latin1 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do - s1 = "Texte encod\xc3\xa9".force_encoding("UTF-8") - s2 = "Texte encod\xe9".force_encoding("ASCII-8BIT") + s1 = 'Texte encodé' + s2 = (+"Texte encod\xe9").force_encoding("ASCII-8BIT") s3 = s2.dup.force_encoding("UTF-8") assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2) assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3) @@ -33,8 +33,8 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase def test_to_utf8_by_setting_from_euc_jp 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".force_encoding("UTF-8") - s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3".force_encoding("ASCII-8BIT") + s1 = 'レッドマイン' + s2 = (+"\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3").force_encoding("ASCII-8BIT") s3 = s2.dup.force_encoding("UTF-8") assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2) assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3) @@ -43,8 +43,8 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase def test_to_utf8_by_setting_should_be_converted_all_latin1 with_settings :repositories_encodings => 'ISO-8859-1' do - s1 = "\xc3\x82\xc2\x80".force_encoding("UTF-8") - s2 = "\xC2\x80".force_encoding("ASCII-8BIT") + s1 = "Â\u0080" + s2 = (+"\xC2\x80").force_encoding("ASCII-8BIT") s3 = s2.dup.force_encoding("UTF-8") assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2) assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3) @@ -57,7 +57,7 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase end def test_to_utf8_by_setting_returns_ascii_as_utf8 - s1 = "ASCII".force_encoding("UTF-8") + s1 = 'ASCII' s2 = s1.dup.force_encoding("ISO-8859-1") str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1) str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2) @@ -69,8 +69,7 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped with_settings :repositories_encodings => '' do - # s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") - s1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT") + s1 = (+"Texte encod\xe9 en ISO-8859-1.").force_encoding("ASCII-8BIT") str = Redmine::CodesetUtil.to_utf8_by_setting(s1) assert str.valid_encoding? assert_equal "UTF-8", str.encoding.to_s @@ -80,7 +79,7 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped_ja_jis with_settings :repositories_encodings => 'ISO-2022-JP' do - s1 = "test\xb5\xfetest\xb5\xfe".force_encoding("ASCII-8BIT") + s1 = (+"test\xb5\xfetest\xb5\xfe").force_encoding("ASCII-8BIT") str = Redmine::CodesetUtil.to_utf8_by_setting(s1) assert str.valid_encoding? assert_equal "UTF-8", str.encoding.to_s @@ -89,18 +88,18 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase end test "#replace_invalid_utf8 should replace invalid utf8" do - s1 = "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xE3\x81\xFF".force_encoding("UTF-8") + s1 = "こんにち\xE3\x81\xFF" s2 = Redmine::CodesetUtil.replace_invalid_utf8(s1) assert s2.valid_encoding? assert_equal "UTF-8", s2.encoding.to_s - assert_equal "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1??".force_encoding("UTF-8"), s2 + assert_equal 'こんにち??', s2 end test "#to_utf8 should replace invalid non utf8" do - s1 = "\xa4\xb3\xa4\xf3\xa4\xcb\xa4\xc1\xa4".force_encoding("EUC-JP") + s1 = (+"\xa4\xb3\xa4\xf3\xa4\xcb\xa4\xc1\xa4").force_encoding("EUC-JP") s2 = Redmine::CodesetUtil.to_utf8(s1, "EUC-JP") assert s2.valid_encoding? assert_equal "UTF-8", s2.encoding.to_s - assert_equal "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1?".force_encoding("UTF-8"), s2 + assert_equal 'こんにち?', s2 end end diff --git a/test/unit/lib/redmine/export/csv_test.rb b/test/unit/lib/redmine/export/csv_test.rb index 69f760af2..c9065521d 100644 --- a/test/unit/lib/redmine/export/csv_test.rb +++ b/test/unit/lib/redmine/export/csv_test.rb @@ -21,13 +21,12 @@ require File.expand_path('../../../../../test_helper', __FILE__) class CsvTest < ActiveSupport::TestCase include Redmine::I18n - BOM = "\xEF\xBB\xBF".force_encoding('UTF-8') def test_should_include_bom_when_utf8_encoded with_locale 'sk' do string = Redmine::Export::CSV.generate {|csv| csv << %w(Foo Bar)} assert_equal 'UTF-8', string.encoding.name - assert string.starts_with?(BOM) + assert string.starts_with?("\xEF\xBB\xBF") end end diff --git a/test/unit/lib/redmine/export/pdf_test.rb b/test/unit/lib/redmine/export/pdf_test.rb index 9e9880c3a..5e3c6ebef 100644 --- a/test/unit/lib/redmine/export/pdf_test.rb +++ b/test/unit/lib/redmine/export/pdf_test.rb @@ -29,16 +29,16 @@ class PdfTest < ActiveSupport::TestCase end def test_rdm_pdf_iconv_cannot_convert_ja_cp932 - utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b" - utf8_txt_2 = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80" - utf8_txt_3 = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80" + utf8_txt_1 = '狀態' + utf8_txt_2 = '狀態狀' + utf8_txt_3 = '狀狀態狀' ["CP932", "SJIS"].each do |encoding| txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding) txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding) txt_3 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding) - assert_equal "?\x91\xd4".force_encoding("ASCII-8BIT"), txt_1 - assert_equal "?\x91\xd4?".force_encoding("ASCII-8BIT"), txt_2 - assert_equal "??\x91\xd4?".force_encoding("ASCII-8BIT"), txt_3 + assert_equal (+"?\x91\xd4").force_encoding("ASCII-8BIT"), txt_1 + assert_equal (+"?\x91\xd4?").force_encoding("ASCII-8BIT"), txt_2 + assert_equal (+"??\x91\xd4?").force_encoding("ASCII-8BIT"), txt_3 assert_equal "ASCII-8BIT", txt_1.encoding.to_s assert_equal "ASCII-8BIT", txt_2.encoding.to_s assert_equal "ASCII-8BIT", txt_3.encoding.to_s @@ -46,8 +46,8 @@ class PdfTest < ActiveSupport::TestCase end def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_en - str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8") - str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT") + str1 = "Texte encod\xE9 en ISO-8859-1" + str2 = (+"\xe9a\xe9b\xe9c\xe9d\xe9e test").force_encoding("ASCII-8BIT") txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, 'UTF-8') txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, 'UTF-8') assert_equal "ASCII-8BIT", txt_1.encoding.to_s @@ -57,8 +57,8 @@ class PdfTest < ActiveSupport::TestCase end def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja - str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8") - str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT") + str1 = "Texte encod\xE9 en ISO-8859-1" + str2 = (+"\xe9a\xe9b\xe9c\xe9d\xe9e test").force_encoding("ASCII-8BIT") encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" ) txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, encoding) txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, encoding) @@ -72,7 +72,7 @@ class PdfTest < ActiveSupport::TestCase ["CP932", "SJIS"].each do |encoding| set_fixtures_attachments_directory - str2 = "\x83e\x83X\x83g".force_encoding("ASCII-8BIT") + str2 = (+"\x83e\x83X\x83g").force_encoding("ASCII-8BIT") a1 = Attachment.find(17) a2 = Attachment.find(19) diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb index 7188c54b9..e99934ac2 100644 --- a/test/unit/lib/redmine/i18n_test.rb +++ b/test/unit/lib/redmine/i18n_test.rb @@ -165,8 +165,7 @@ class Redmine::I18nTest < ActiveSupport::TestCase set_language_if_valid 'bs' assert_equal "KM -1000,20", number_to_currency(-1000.2) set_language_if_valid 'de' - euro_sign = "\xe2\x82\xac".force_encoding('UTF-8') - assert_equal "-1000,20 #{euro_sign}", number_to_currency(-1000.2) + assert_equal '-1000,20 €', number_to_currency(-1000.2) end def test_lu_should_not_error_when_user_language_is_an_empty_string @@ -191,8 +190,7 @@ class Redmine::I18nTest < ActiveSupport::TestCase assert_nil options.detect {|option| option.size != 2} assert_nil options.detect {|option| !option.first.is_a?(String) || !option.last.is_a?(String)} assert_include ["English", "en"], options - ja = "Japanese (\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e)".force_encoding('UTF-8') - assert_include [ja, "ja"], options + assert_include ['Japanese (日本語)', "ja"], options end def test_languages_options_should_return_strings_with_utf8_encoding @@ -243,21 +241,18 @@ class Redmine::I18nTest < ActiveSupport::TestCase def test_utf8 set_language_if_valid 'ja' - str_ja_yes = "\xe3\x81\xaf\xe3\x81\x84".force_encoding('UTF-8') i18n_ja_yes = l(:general_text_Yes) - assert_equal str_ja_yes, i18n_ja_yes + assert_equal 'はい', i18n_ja_yes assert_equal "UTF-8", i18n_ja_yes.encoding.to_s end def test_traditional_chinese_locale set_language_if_valid 'zh-TW' - str_tw = "Chinese/Traditional (\xE7\xB9\x81\xE9\xAB\x94\xE4\xB8\xAD\xE6\x96\x87)".force_encoding('UTF-8') - assert_equal str_tw, l(:general_lang_name) + assert_equal 'Chinese/Traditional (繁體中文)', l(:general_lang_name) end def test_french_locale set_language_if_valid 'fr' - str_fr = "French (Fran\xc3\xa7ais)".force_encoding('UTF-8') - assert_equal str_fr, l(:general_lang_name) + assert_equal 'French (Français)', l(:general_lang_name) end end diff --git a/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb index 5a942491e..e1df2d975 100644 --- a/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb @@ -22,9 +22,6 @@ require File.expand_path('../../../../../../test_helper', __FILE__) class GitAdapterTest < ActiveSupport::TestCase REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s - FELIX_HEX = "Felix Sch\xC3\xA4fer" - CHAR_1_HEX = "\xc3\x9c" - ## Git, Mercurial and CVS path encodings are binary. ## Subversion supports URL encoding for path. ## Redmine Mercurial adapter and extension use URL encoding. @@ -60,8 +57,8 @@ class GitAdapterTest < ActiveSupport::TestCase 'ISO-8859-1' ) assert @adapter - @char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8') - @str_felix_hex = FELIX_HEX.dup.force_encoding('ASCII-8BIT') + @char_1 = 'Ü' + @str_felix_hex = (+"Felix Sch\xC3\xA4fer").force_encoding('ASCII-8BIT') end def test_scm_version diff --git a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb index aa2dc8ae0..1c9d94831 100644 --- a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb @@ -27,7 +27,6 @@ class MercurialAdapterTest < ActiveSupport::TestCase HgCommandArgumentError = Redmine::Scm::Adapters::MercurialAdapter::HgCommandArgumentError REPOSITORY_PATH = repository_path('mercurial') - CHAR_1_HEX = "\xc3\x9c" if File.directory?(REPOSITORY_PATH) def setup @@ -44,10 +43,10 @@ class MercurialAdapterTest < ActiveSupport::TestCase nil, 'ISO-8859-1') @diff_c_support = true - @char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8') - @tag_char_1 = "tag-#{CHAR_1_HEX}-00".force_encoding('UTF-8') - @branch_char_0 = "branch-#{CHAR_1_HEX}-00".force_encoding('UTF-8') - @branch_char_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8') + @char_1 = 'Ü' + @tag_char_1 = 'tag-Ü-00' + @branch_char_0 = 'branch-Ü-00' + @branch_char_1 = 'branch-Ü-01' end def test_hgversion diff --git a/test/unit/lib/redmine/unified_diff_test.rb b/test/unit/lib/redmine/unified_diff_test.rb index efd7780d9..ff5174e03 100644 --- a/test/unit/lib/redmine/unified_diff_test.rb +++ b/test/unit/lib/redmine/unified_diff_test.rb @@ -274,23 +274,20 @@ DIFF end def test_utf8_ja - ja = " text_tip_issue_end_day: " - ja += "\xe3\x81\x93\xe3\x81\xae\xe6\x97\xa5\xe3\x81\xab\xe7\xb5\x82\xe4\xba\x86\xe3\x81\x99\xe3\x82\x8b<span>\xe3\x82\xbf\xe3\x82\xb9\xe3\x82\xaf</span>".force_encoding('UTF-8') with_settings :repositories_encodings => '' do diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ja.diff'), :type => 'inline') assert_equal 1, diff.size assert_equal 12, diff.first.size - assert_equal ja, diff.first[4].html_line_left + assert_equal ' text_tip_issue_end_day: この日に終了する<span>タスク</span>', diff.first[4].html_line_left end end def test_utf8_ru - ru = " other: "\xd0\xbe\xd0\xba\xd0\xbe\xd0\xbb\xd0\xbe %{count} \xd1\x87\xd0\xb0\xd1\x81<span>\xd0\xb0</span>"".force_encoding('UTF-8') with_settings :repositories_encodings => '' do diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ru.diff'), :type => 'inline') assert_equal 1, diff.size assert_equal 8, diff.first.size - assert_equal ru, diff.first[3].html_line_left + assert_equal ' other: "около %{count} час<span>а</span>"', diff.first[3].html_line_left end end @@ -329,70 +326,60 @@ DIFF end def test_offset_range_japanese_1 - ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span></span>".force_encoding('UTF-8') - ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x9e</span>".force_encoding('UTF-8') with_settings :repositories_encodings => '' do diff = Redmine::UnifiedDiff.new( read_diff_fixture('issue-13644-1.diff'), :type => 'sbs') assert_equal 1, diff.size assert_equal 3, diff.first.size - assert_equal ja1, diff.first[1].html_line_left - assert_equal ja2, diff.first[1].html_line_right + assert_equal '日本<span></span>', diff.first[1].html_line_left + assert_equal '日本<span>語</span>', diff.first[1].html_line_right end end def test_offset_range_japanese_2 - ja1 = "<span></span>\xe6\x97\xa5\xe6\x9c\xac".force_encoding('UTF-8') - ja2 = "<span>\xe3\x81\xab\xe3\x81\xa3\xe3\x81\xbd\xe3\x82\x93</span>\xe6\x97\xa5\xe6\x9c\xac".force_encoding('UTF-8') with_settings :repositories_encodings => '' do diff = Redmine::UnifiedDiff.new( read_diff_fixture('issue-13644-2.diff'), :type => 'sbs') assert_equal 1, diff.size assert_equal 3, diff.first.size - assert_equal ja1, diff.first[1].html_line_left - assert_equal ja2, diff.first[1].html_line_right + assert_equal '<span></span>日本', diff.first[1].html_line_left + assert_equal '<span>にっぽん</span>日本', diff.first[1].html_line_right end end def test_offset_range_japanese_3 # UTF-8 The 1st byte differs. - ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>".force_encoding('UTF-8') - ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe5\xa8\x98</span>".force_encoding('UTF-8') with_settings :repositories_encodings => '' do diff = Redmine::UnifiedDiff.new( read_diff_fixture('issue-13644-3.diff'), :type => 'sbs') assert_equal 1, diff.size assert_equal 3, diff.first.size - assert_equal ja1, diff.first[1].html_line_left - assert_equal ja2, diff.first[1].html_line_right + assert_equal '日本<span>記</span>', diff.first[1].html_line_left + assert_equal '日本<span>娘</span>', diff.first[1].html_line_right end end def test_offset_range_japanese_4 # UTF-8 The 2nd byte differs. - ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>".force_encoding('UTF-8') - ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>".force_encoding('UTF-8') with_settings :repositories_encodings => '' do diff = Redmine::UnifiedDiff.new( read_diff_fixture('issue-13644-4.diff'), :type => 'sbs') assert_equal 1, diff.size assert_equal 3, diff.first.size - assert_equal ja1, diff.first[1].html_line_left - assert_equal ja2, diff.first[1].html_line_right + assert_equal '日本<span>記</span>', diff.first[1].html_line_left + assert_equal '日本<span>誘</span>', diff.first[1].html_line_right end end def test_offset_range_japanese_5 # UTF-8 The 2nd byte differs. - ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>ok".force_encoding('UTF-8') - ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>ok".force_encoding('UTF-8') with_settings :repositories_encodings => '' do diff = Redmine::UnifiedDiff.new( read_diff_fixture('issue-13644-5.diff'), :type => 'sbs') assert_equal 1, diff.size assert_equal 3, diff.first.size - assert_equal ja1, diff.first[1].html_line_left - assert_equal ja2, diff.first[1].html_line_right + assert_equal '日本<span>記</span>ok', diff.first[1].html_line_left + assert_equal '日本<span>誘</span>ok', diff.first[1].html_line_right end end |