scm: replace invalid utf-8 sequences instead of stripping in displaying repository contents on Ruby 1.8.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5427 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
62952a9885
commit
bb48d96d30
|
@ -156,12 +156,18 @@ module RepositoriesHelper
|
||||||
:undef => :replace, :replace => '?').encode("UTF-8")
|
:undef => :replace, :replace => '?').encode("UTF-8")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# removes invalid UTF8 sequences
|
ic = Iconv.new('UTF-8', 'UTF-8')
|
||||||
|
txtar = ""
|
||||||
begin
|
begin
|
||||||
str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
|
txtar += ic.iconv(str)
|
||||||
rescue Iconv::InvalidEncoding
|
rescue Iconv::IllegalSequence
|
||||||
# "UTF-8//IGNORE" is not supported on some OS
|
txtar += $!.success
|
||||||
|
str = '?' + $!.failed[1,$!.failed.length]
|
||||||
|
retry
|
||||||
|
rescue
|
||||||
|
txtar += $!.success
|
||||||
end
|
end
|
||||||
|
str = txtar
|
||||||
end
|
end
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,12 +94,10 @@ class RepositoryHelperTest < HelperTestCase
|
||||||
s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
|
s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
|
||||||
str = to_utf8(s1)
|
str = to_utf8(s1)
|
||||||
if str.respond_to?(:force_encoding)
|
if str.respond_to?(:force_encoding)
|
||||||
assert_equal "Texte encod? en ISO-8859-1.", str
|
|
||||||
assert str.valid_encoding?
|
assert str.valid_encoding?
|
||||||
assert_equal "UTF-8", str.encoding.to_s
|
assert_equal "UTF-8", str.encoding.to_s
|
||||||
else
|
|
||||||
assert_equal "Texte encod en ISO-8859-1.", str
|
|
||||||
end
|
end
|
||||||
|
assert_equal "Texte encod? en ISO-8859-1.", str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue