Defect #24910 » converter_not_found.patch
| lib/redmine/codeset_util.rb (working copy) | ||
|---|---|---|
|
end
|
||
|
enc = encoding.blank? ? "UTF-8" : encoding
|
||
|
if enc.casecmp("UTF-8") != 0
|
||
|
str.force_encoding(enc)
|
||
|
str = str.encode("UTF-8", :invalid => :replace,
|
||
|
begin
|
||
|
str.force_encoding(enc)
|
||
|
str = str.encode("UTF-8", :invalid => :replace,
|
||
|
:undef => :replace, :replace => '?')
|
||
|
rescue Encoding::ConverterNotFoundError
|
||
|
Rails.logger.warn ">>> ConverterNotFoundError (#{enc} to UTF-8)"
|
||
|
str = replace_invalid_utf8(str)
|
||
|
end
|
||
|
else
|
||
|
str = replace_invalid_utf8(str)
|
||
|
end
|
||
| test/unit/lib/redmine/codeset_util_test.rb (working copy) | ||
|---|---|---|
|
assert_equal "UTF-8", s2.encoding.to_s
|
||
|
assert_equal 'こんにち?', s2
|
||
|
end
|
||
|
test "#to_utf8 should support not supported code page" do
|
||
|
s1 = (+'không hợp lệ').force_encoding('Windows-1258')
|
||
|
s2 = Redmine::CodesetUtil.to_utf8(s1, 'Windows-1258')
|
||
|
assert s2.valid_encoding?
|
||
|
assert_equal 'UTF-8', s2.encoding.to_s
|
||
|
assert_equal 'không hợp lệ', s2
|
||
|
end
|
||
|
end
|
||