scm: fix repository helper unit test fails in Ruby 1.9 and non UTF-8 locale.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5158 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-03-17 03:51:46 +00:00 committed by Eric Davis
parent f34a566c75
commit 24db8296b8
2 changed files with 14 additions and 10 deletions

View File

@ -117,16 +117,15 @@ module RepositoriesHelper
end
def to_utf8(str)
return str if str.blank?
return str if str.nil?
if str.respond_to?(:force_encoding)
str.force_encoding('ASCII-8BIT')
end
return str if str.empty?
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
if str.respond_to?(:force_encoding)
str.force_encoding('UTF-8')
else
# TODO:
# Japanese Shift_JIS(CP932) is not compatible with ASCII.
# UTF-7 and Japanese ISO-2022-JP are 7bits clean.
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
end
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
@encodings.each do |encoding|
begin

View File

@ -24,7 +24,7 @@ class RepositoryHelperTest < HelperTestCase
with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
s1 = "Texte encod\xc3\xa9"
s2 = "Texte encod\xe9"
s3 = s2
s3 = s2.dup
if s1.respond_to?(:force_encoding)
s1.force_encoding("UTF-8")
s2.force_encoding("ASCII-8BIT")
@ -39,7 +39,7 @@ class RepositoryHelperTest < HelperTestCase
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"
s3 = s2
s3 = s2.dup
if s1.respond_to?(:force_encoding)
s1.force_encoding("UTF-8")
s2.force_encoding("ASCII-8BIT")
@ -54,7 +54,7 @@ class RepositoryHelperTest < HelperTestCase
with_settings :repositories_encodings => 'ISO-8859-1' do
s1 = "\xc3\x82\xc2\x80"
s2 = "\xC2\x80"
s3 = s2
s3 = s2.dup
if s1.respond_to?(:force_encoding)
s1.force_encoding("UTF-8")
s2.force_encoding("ASCII-8BIT")
@ -64,5 +64,10 @@ class RepositoryHelperTest < HelperTestCase
assert_equal s1, to_utf8(s3)
end
end
def test_to_utf8_blank_string
assert_equal "", to_utf8("")
assert_equal nil, to_utf8(nil)
end
end