Commit 5a9962ff authored by maeda's avatar maeda

Decode hexadecimal-encoded literals in order to be frozen string literals friendly (#31004).

Patch by Yuichi HARADA.


git-svn-id: https://svn.redmine.org/redmine/trunk@17991 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 110f6491
......@@ -143,8 +143,6 @@ class AttachmentsControllerTest < Redmine::ControllerTest
assert a.save
assert_equal 'japanese-utf-8.txt', a.filename
str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
get :show, :params => {
:id => a.id
}
......@@ -152,7 +150,7 @@ class AttachmentsControllerTest < Redmine::ControllerTest
assert_equal 'text/html', @response.content_type
assert_select 'tr#L1' do
assert_select 'th.line-num', :text => '1'
assert_select 'td', :text => /#{str_japanese}/
assert_select 'td', :text => /日本語/
end
end
......
......@@ -772,8 +772,8 @@ class IssuesControllerTest < Redmine::ControllerTest
def test_index_csv_big_5
with_settings :default_language => "zh-TW" do
str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5')
str_utf8 = '一月'
str_big5 = (+"\xa4@\xa4\xeb").force_encoding('Big5')
issue = Issue.generate!(:subject => str_utf8)
get :index, :params => {
......@@ -784,7 +784,7 @@ class IssuesControllerTest < Redmine::ControllerTest
assert_equal 'text/csv; header=present', @response.content_type
lines = @response.body.chomp.split("\n")
header = lines[0]
status = "\xaa\xac\xbaA".force_encoding('Big5')
status = (+"\xaa\xac\xbaA").force_encoding('Big5')
assert_include status, header
issue_line = lines.find {|l| l =~ /^#{issue.id},/}
assert_include str_big5, issue_line
......@@ -793,7 +793,7 @@ class IssuesControllerTest < Redmine::ControllerTest
def test_index_csv_cannot_convert_should_be_replaced_big_5
with_settings :default_language => "zh-TW" do
str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
str_utf8 = '以内'
issue = Issue.generate!(:subject => str_utf8)
get :index, :params => {
......@@ -807,10 +807,10 @@ class IssuesControllerTest < Redmine::ControllerTest
lines = @response.body.chomp.split("\n")
header = lines[0]
issue_line = lines.find {|l| l =~ /^#{issue.id},/}
s1 = "\xaa\xac\xbaA".force_encoding('Big5') # status
s1 = (+"\xaa\xac\xbaA").force_encoding('Big5') # status
assert header.include?(s1)
s2 = issue_line.split(",")[2]
s3 = "\xa5H?".force_encoding('Big5') # subject
s3 = (+"\xa5H?").force_encoding('Big5') # subject
assert_equal s3, s2
end
end
......@@ -2345,10 +2345,7 @@ class IssuesControllerTest < Redmine::ControllerTest
end
def test_export_to_pdf_with_utf8_u_fffd
# U+FFFD
s = "\xef\xbf\xbd"
s.force_encoding('UTF-8') if s.respond_to?(:force_encoding)
issue = Issue.generate!(:subject => s)
issue = Issue.generate!(:subject => "�")
["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
with_settings :default_language => lang do
get :show, :params => {
......
......@@ -28,7 +28,6 @@ class RepositoriesBazaarControllerTest < Redmine::RepositoryControllerTest
REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
PRJ_ID = 3
CHAR_1_UTF8_HEX = "\xc3\x9c".dup.force_encoding('UTF-8')
def setup
super
......@@ -224,7 +223,7 @@ class RepositoriesBazaarControllerTest < Redmine::RepositoryControllerTest
assert_select "th.line-num", :text => '1' do
assert_select "+ td.revision" do
assert_select "a", :text => '2'
assert_select "+ td.author", :text => "test #{CHAR_1_UTF8_HEX}" do
assert_select "+ td.author", :text => "test Ü" do
assert_select "+ td",
:text => "author non ASCII test"
end
......
......@@ -112,8 +112,7 @@ class RepositoriesFilesystemControllerTest < Redmine::RepositoryControllerTest
"when Encoding.default_external is not UTF-8. " +
"Current value is '#{Encoding.default_external.to_s}'"
else
str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
assert_select 'tr#L3 td.line-code', :text => /#{str_japanese}/
assert_select 'tr#L3 td.line-code', :text => /日本語/
end
end
end
......
......@@ -28,8 +28,6 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
PRJ_ID = 3
CHAR_1_HEX = "\xc3\x9c".force_encoding('UTF-8')
FELIX_HEX = "Felix Sch\xC3\xA4fer".force_encoding('UTF-8')
NUM_REV = 28
## Git, Mercurial and CVS path encodings are binary.
......@@ -269,11 +267,11 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
get :entry, :params => {
:id => PRJ_ID,
:repository_id => @repository.id,
:path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
:path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
:rev => r1
}
assert_response :success
assert_select 'tr#L1 td.line-code', :text => /test-#{CHAR_1_HEX}.txt/
assert_select 'tr#L1 td.line-code', :text => /test-Ü.txt/
end
end
end
......@@ -440,8 +438,8 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
}
assert_response :success
assert_select 'table' do
assert_select 'thead th.filename', :text => /latin-1-dir\/test-#{CHAR_1_HEX}.txt/
assert_select 'tbody td.diff_in', :text => /test-#{CHAR_1_HEX}.txt/
assert_select 'thead th.filename', :text => /latin-1-dir\/test-Ü.txt/
assert_select 'tbody td.diff_in', :text => /test-Ü.txt/
end
end
end
......@@ -568,7 +566,7 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
get :annotate, :params => {
:id => PRJ_ID,
:repository_id => @repository.id,
:path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
:path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
:rev => r1
}
assert_select "th.line-num", :text => '1' do
......@@ -576,7 +574,7 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
assert_select "a", :text => '57ca437c'
assert_select "+ td.author", :text => "jsmith" do
assert_select "+ td",
:text => "test-#{CHAR_1_HEX}.txt"
:text => "test-Ü.txt"
end
end
end
......@@ -596,7 +594,7 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
assert_select "th.line-num", :text => '1' do
assert_select "+ td.revision" do
assert_select "a", :text => '83ca5fd5'
assert_select "+ td.author", :text => FELIX_HEX do
assert_select "+ td.author", :text => "Felix Schäfer" do
assert_select "+ td",
:text => "And this is a file with a leading and trailing space..."
end
......
......@@ -26,7 +26,6 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
:repositories, :enabled_modules
REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
CHAR_1_HEX = "\xc3\x9c"
PRJ_ID = 3
NUM_REV = 34
......@@ -43,10 +42,6 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
)
assert @repository
@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')
end
if ruby19_non_utf8_pass
......@@ -186,9 +181,9 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
assert_select 'table.entries tbody' do
assert_select 'tr', 4
assert_select 'tr.file td.filename a', :text => "make-latin-1-file.rb"
assert_select 'tr.file td.filename a', :text => "test-#{@char_1}-1.txt"
assert_select 'tr.file td.filename a', :text => "test-#{@char_1}-2.txt"
assert_select 'tr.file td.filename a', :text => "test-#{@char_1}.txt"
assert_select 'tr.file td.filename a', :text => "test-Ü-1.txt"
assert_select 'tr.file td.filename a', :text => "test-Ü-2.txt"
assert_select 'tr.file td.filename a', :text => "test-Ü.txt"
end
assert_select 'table.changesets tbody' do
......@@ -221,9 +216,9 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
assert_equal NUM_REV, @repository.changesets.count
[
'default',
@branch_char_1,
'branch-Ü-01',
'branch (1)[2]&,%.-3_4',
@branch_char_0,
'branch-Ü-00',
'test_branch.latin-1',
'test-branch-00',
].each do |bra|
......@@ -245,7 +240,7 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
@project.reload
assert_equal NUM_REV, @repository.changesets.count
[
@tag_char_1,
'tag-Ü-00',
'tag_test.00',
'tag-init-revision'
].each do |tag|
......@@ -287,7 +282,7 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
get :entry, :params => {
:id => PRJ_ID,
:repository_id => @repository.id,
:path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
:path => repository_path_hash(['latin-1-dir', "test-Ü-2.txt"])[:param],
:rev => r1
}
assert_response :success
......@@ -301,11 +296,11 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
get :entry, :params => {
:id => PRJ_ID,
:repository_id => @repository.id,
:path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
:path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
:rev => r1
}
assert_response :success
assert_select 'tr#L1 td.line-code', :text => /test-#{@char_1}.txt/
assert_select 'tr#L1 td.line-code', :text => /test-Ü.txt/
end
end
end
......@@ -395,7 +390,7 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
}
assert_response :success
assert_select 'table' do
assert_select 'thead th.filename', :text => /latin-1-dir\/test-#{@char_1}-2.txt/
assert_select 'thead th.filename', :text => /latin-1-dir\/test-Ü-2.txt/
assert_select 'tbody td.diff_in', :text => /It is written in Python/
end
end
......@@ -478,7 +473,7 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
get :annotate, :params => {
:id => PRJ_ID,
:repository_id => @repository.id,
:path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
:path => repository_path_hash(['latin-1-dir', "test-Ü-2.txt"])[:param],
:rev => r1
}
assert_response :success
......@@ -500,10 +495,10 @@ class RepositoriesMercurialControllerTest < Redmine::RepositoryControllerTest
get :annotate, :params => {
:id => PRJ_ID,
:repository_id => @repository.id,
:path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
:path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
:rev => r1
}
assert_select 'tr#L1 td.line-code', :text => /test-#{@char_1}.txt/
assert_select 'tr#L1 td.line-code', :text => /test-Ü.txt/
end
end
end
......
......@@ -260,10 +260,9 @@ class TimelogReportTest < Redmine::ControllerTest
end
def test_csv_big_5
str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5')
str_big5 = (+"\xa4@\xa4\xeb").force_encoding('Big5')
user = User.find_by_id(3)
user.firstname = str_utf8
user.firstname = "一月"
user.lastname = "test-lastname"
assert user.save
comments = "test_csv_big_5"
......@@ -293,24 +292,22 @@ class TimelogReportTest < Redmine::ControllerTest
assert_equal 'text/csv; header=present', @response.content_type
lines = @response.body.chomp.split("\n")
# Headers
s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
s2 = "\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
s1 = (+"\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp").force_encoding('Big5')
s2 = (+"\xa4u\xae\xc9\xc1`\xadp").force_encoding('Big5')
assert_equal s1, lines.first
# Total row
assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1]
assert_equal "#{s2},7.30,7.30", lines[2]
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)
assert_equal 'Big5', l(:general_csv_encoding)
assert_equal ',', l(:general_csv_separator)
assert_equal '.', l(:general_csv_decimal_separator)
end
def test_csv_cannot_convert_should_be_replaced_big_5
str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
user = User.find_by_id(3)
user.firstname = str_utf8
user.firstname = "以内"
user.lastname = "test-lastname"
assert user.save
comments = "test_replaced"
......@@ -340,10 +337,10 @@ class TimelogReportTest < Redmine::ControllerTest
assert_equal 'text/csv; header=present', @response.content_type
lines = @response.body.chomp.split("\n")
# Headers
s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
s1 = (+"\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp").force_encoding('Big5')
assert_equal s1, lines.first
# Total row
s2 = "\xa5H?".force_encoding('Big5')
s2 = (+"\xa5H?").force_encoding('Big5')
assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1]
end
......@@ -375,15 +372,14 @@ class TimelogReportTest < Redmine::ControllerTest
assert_equal 'text/csv; header=present', @response.content_type
lines = @response.body.chomp.split("\n")
# Headers
s1 = "Utilisateur;2011-11-11;Temps total".force_encoding('ISO-8859-1')
s2 = "Temps total".force_encoding('ISO-8859-1')
s1 = (+"Utilisateur;2011-11-11;Temps total").force_encoding('ISO-8859-1')
s2 = (+"Temps total").force_encoding('ISO-8859-1')
assert_equal s1, lines.first
# Total row
assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1]
assert_equal "#{s2};7,30;7,30", lines[2]
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)
assert_equal 'ISO-8859-1', l(:general_csv_encoding)
assert_equal ';', l(:general_csv_separator)
assert_equal ',', l(:general_csv_decimal_separator)
......
......@@ -37,7 +37,7 @@ class ApplicationHelperTest < Redmine::HelperTest
def setup
super
set_tmp_attachments_directory
@russian_test = "\xd1\x82\xd0\xb5\xd1\x81\xd1\x82".force_encoding('UTF-8')
@russian_test = 'тест'
end
test "#link_to_if_authorized for authorized user should allow using the :controller and :action for the target link" do
......@@ -1792,7 +1792,7 @@ RAW
end
def test_truncate_single_line_non_ascii
ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
ja = '日本語'
result = truncate_single_line_raw("#{ja}\n#{ja}\n#{ja}", 10)
assert_equal "#{ja} #{ja}...", result
assert !result.html_safe?
......
......@@ -112,7 +112,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base
end
def test_invalid_utf8_credentials_should_not_trigger_an_error
invalid_utf8 = "\x82".force_encoding('UTF-8')
invalid_utf8 = "\x82"
assert !invalid_utf8.valid_encoding?
assert_nothing_raised do
get '/users/current.xml', :headers => credentials(invalid_utf8, "foo")
......
......@@ -408,7 +408,7 @@ class AttachmentTest < ActiveSupport::TestCase
end
def test_latest_attach_should_not_error_with_string_with_invalid_encoding
string = "width:50\xFE-Image.jpg".force_encoding('UTF-8')
string = "width:50\xFE-Image.jpg"
assert_equal false, string.valid_encoding?
Attachment.latest_attach(Attachment.limit(2).to_a, string)
......
......@@ -448,8 +448,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_comments_should_be_converted_to_utf8
proj = Project.find(3)
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
str = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT")
str = (+"Texte encod\xe9 en ISO-8859-1.").force_encoding("ASCII-8BIT")
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
......@@ -461,15 +460,12 @@ class ChangesetTest < ActiveSupport::TestCase
:scmid => '12345',
:comments => str)
assert( c.save )
str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1.".force_encoding("UTF-8")
assert_equal str_utf8, c.comments
assert_equal 'Texte encodé en ISO-8859-1.', c.comments
end
def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
proj = Project.find(3)
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
str1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("UTF-8")
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
str2 = (+"\xe9a\xe9b\xe9c\xe9d\xe9e test").force_encoding("ASCII-8BIT")
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
......@@ -479,7 +475,7 @@ class ChangesetTest < ActiveSupport::TestCase
:committed_on => Time.now,
:revision => '123',
:scmid => '12345',
:comments => str1,
:comments => "Texte encod\xE9 en ISO-8859-1.",
:committer => str2)
assert( c.save )
assert_equal "Texte encod? en ISO-8859-1.", c.comments
......@@ -488,7 +484,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
proj = Project.find(3)
str = "test\xb5\xfetest\xb5\xfe".force_encoding('ASCII-8BIT')
str = (+"test\xb5\xfetest\xb5\xfe").force_encoding('ASCII-8BIT')
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
......@@ -504,8 +500,8 @@ class ChangesetTest < ActiveSupport::TestCase
end
def test_comments_should_be_converted_all_latin1_to_utf8
s1 = "\xC2\x80"
s2 = "\xc3\x82\xc2\x80"
s1 = +"\xC2\x80"
s2 = +"\xc3\x82\xc2\x80"
s4 = s2.dup
s3 = s1.dup
s1.force_encoding('ASCII-8BIT')
......@@ -530,8 +526,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_invalid_utf8_sequences_in_paths_should_be_replaced
proj = Project.find(3)
str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
str2 = (+"\xe9a\xe9b\xe9c\xe9d\xe9e test").force_encoding("ASCII-8BIT")
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
......@@ -547,7 +542,7 @@ class ChangesetTest < ActiveSupport::TestCase
ch = Change.new(
:changeset => cs,
:action => "A",
:path => str1,
:path => "Texte encod\xE9 en ISO-8859-1",
:from_path => str2,
:from_revision => "345")
assert(ch.save)
......
......@@ -107,7 +107,7 @@ class CustomFieldTest < ActiveSupport::TestCase
def test_possible_values_should_return_utf8_encoded_strings
field = CustomField.new
s = "Value".force_encoding('BINARY')
s = (+"Value").force_encoding('BINARY')
field.possible_values = s
assert_equal [s], field.possible_values
assert_equal 'UTF-8', field.possible_values.first.encoding.name
......
......@@ -58,10 +58,9 @@ class GroupTest < ActiveSupport::TestCase
def test_blank_name_error_message_fr
set_language_if_valid 'fr'
str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
g = Group.new
assert !g.save
assert_include str, g.errors.full_messages
assert_include 'Nom doit être renseigné(e)', g.errors.full_messages
end
def test_group_roles_should_be_given_to_added_user
......
......@@ -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
......@@ -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
......
......@@ -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)
......
......@@ -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
......@@ -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
......
......@@ -27,7 +27,6 @@ class MercurialAdapterTest < ActiveSupport::TestCase
HgCommandArgumentError = Redmine::Scm::Adapters::MercurialAdapter::HgCommandArgumentError